diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-01-05 00:57:27 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-01-09 10:41:17 +0100 |
commit | 596f020e904b2da2dac1bc080eb69f66deb998d7 (patch) | |
tree | 31295a77b8895b9a72d8958023fac3db6d8f35fb /src/nvim/assert.h | |
parent | 6b6a4d63ec585badcd69890608bc144ef4d89af7 (diff) | |
download | rneovim-596f020e904b2da2dac1bc080eb69f66deb998d7.tar.gz rneovim-596f020e904b2da2dac1bc080eb69f66deb998d7.tar.bz2 rneovim-596f020e904b2da2dac1bc080eb69f66deb998d7.zip |
PVS/V1028: cast operands, not the result
Diffstat (limited to 'src/nvim/assert.h')
-rw-r--r-- | src/nvim/assert.h | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/nvim/assert.h b/src/nvim/assert.h index 48c5363d5a..3f985475a7 100644 --- a/src/nvim/assert.h +++ b/src/nvim/assert.h @@ -15,10 +15,6 @@ # define __has_extension __has_feature #endif -#ifndef __has_builtin -# define __has_builtin __has_feature -#endif - /// @def STATIC_ASSERT /// @brief Assert at compile time if condition is not satisfied. /// @@ -136,20 +132,22 @@ /// /// @param MAX Maximum value of the narrowest type of operand. /// Not used if compiler supports __builtin_add_overflow. -#if __has_builtin(__builtin_add_overflow) -# define STRICT_ADD(a, b, c) \ +#if (defined(__clang__) && __has_builtin(__builtin_add_overflow)) \ + || (__GNUC__ >= 5) +# define STRICT_ADD(a, b, c, t) \ do { if (__builtin_add_overflow(a, b, c)) { abort(); } } while (0) #else -# define STRICT_ADD(a, b, c) \ - do { *c = a + b; } while (0) +# define STRICT_ADD(a, b, c, t) \ + do { *(c) = (t)(a + b); } while (0) #endif -#if __has_builtin(__builtin_sub_overflow) -# define STRICT_SUB(a, b, c) \ +#if (defined(__clang__) && __has_builtin(__builtin_sub_overflow)) \ + || (__GNUC__ >= 5) +# define STRICT_SUB(a, b, c, t) \ do { if (__builtin_sub_overflow(a, b, c)) { abort(); } } while (0) #else -# define STRICT_SUB(a, b, c) \ - do { *c = a - b; } while (0) +# define STRICT_SUB(a, b, c, t) \ + do { *(c) = (t)(a - b); } while (0) #endif #endif // NVIM_ASSERT_H |