diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-13 15:48:09 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-01-13 18:50:47 -0500 |
commit | afc0e461e123489808930e5433f0d8b3f95d9256 (patch) | |
tree | 0ac45b4bbc1c55890555cddf394b2d056502e9ea /Userland/Libraries/LibVideo | |
parent | 3de75f6436a1e729691a40c35e8e8a5be5aa2f41 (diff) | |
download | serenity-afc0e461e123489808930e5433f0d8b3f95d9256.zip |
AK+Everywhere: Disallow returning a reference from a fallible expression
This will silently make a copy. Rather than masking this behavior, let's
explicitly disallow it.
Diffstat (limited to 'Userland/Libraries/LibVideo')
-rw-r--r-- | Userland/Libraries/LibVideo/DecoderError.h | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/PlaybackManager.cpp | 2 |
2 files changed, 13 insertions, 9 deletions
diff --git a/Userland/Libraries/LibVideo/DecoderError.h b/Userland/Libraries/LibVideo/DecoderError.h index 402b9c8c22..94a7b73993 100644 --- a/Userland/Libraries/LibVideo/DecoderError.h +++ b/Userland/Libraries/LibVideo/DecoderError.h @@ -77,15 +77,17 @@ private: DeprecatedString m_description; }; -#define DECODER_TRY(category, expression) \ - ({ \ - auto _result = ((expression)); \ - if (_result.is_error()) [[unlikely]] { \ - auto _error_string = _result.release_error().string_literal(); \ - return DecoderError::from_source_location( \ - ((category)), _error_string, SourceLocation::current()); \ - } \ - _result.release_value(); \ +#define DECODER_TRY(category, expression) \ + ({ \ + auto _result = ((expression)); \ + if (_result.is_error()) [[unlikely]] { \ + auto _error_string = _result.release_error().string_literal(); \ + return DecoderError::from_source_location( \ + ((category)), _error_string, SourceLocation::current()); \ + } \ + static_assert(!IsLvalueReference<decltype(_result.release_value())>, \ + "Do not return a reference from a fallible expression"); \ + _result.release_value(); \ }) #define DECODER_TRY_ALLOC(expression) DECODER_TRY(DecoderErrorCategory::Memory, expression) diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index 77d881a8fb..acb14feefb 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -273,6 +273,8 @@ bool PlaybackManager::decode_and_queue_one_sample() m_present_timer->start(0); \ return false; \ } \ + static_assert(!IsLvalueReference<decltype(_temporary_result.release_value())>, \ + "Do not return a reference from a fallible expression"); \ _temporary_result.release_value(); \ }) |