mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
STRICT_ADD, STRICT_SUB: Log error before abort
This commit is contained in:
@@ -137,7 +137,12 @@
|
|||||||
/// Not used if compiler supports __builtin_add_overflow.
|
/// Not used if compiler supports __builtin_add_overflow.
|
||||||
#ifdef HAVE_BUILTIN_ADD_OVERFLOW
|
#ifdef HAVE_BUILTIN_ADD_OVERFLOW
|
||||||
# define STRICT_ADD(a, b, c, t) \
|
# define STRICT_ADD(a, b, c, t) \
|
||||||
do { if (__builtin_add_overflow(a, b, c)) { abort(); } } while (0)
|
do { \
|
||||||
|
if (__builtin_add_overflow(a, b, c)) { \
|
||||||
|
ELOG("STRICT_ADD overflow"); \
|
||||||
|
abort(); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#else
|
#else
|
||||||
# define STRICT_ADD(a, b, c, t) \
|
# define STRICT_ADD(a, b, c, t) \
|
||||||
do { *(c) = (t)(a + b); } while (0)
|
do { *(c) = (t)(a + b); } while (0)
|
||||||
@@ -147,7 +152,12 @@
|
|||||||
/// @brief Subtracts (a - b) and stores result in `c`. Aborts on overflow.
|
/// @brief Subtracts (a - b) and stores result in `c`. Aborts on overflow.
|
||||||
#ifdef HAVE_BUILTIN_ADD_OVERFLOW
|
#ifdef HAVE_BUILTIN_ADD_OVERFLOW
|
||||||
# define STRICT_SUB(a, b, c, t) \
|
# define STRICT_SUB(a, b, c, t) \
|
||||||
do { if (__builtin_sub_overflow(a, b, c)) { abort(); } } while (0)
|
do { \
|
||||||
|
if (__builtin_sub_overflow(a, b, c)) { \
|
||||||
|
ELOG("STRICT_SUB overflow"); \
|
||||||
|
abort(); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#else
|
#else
|
||||||
# define STRICT_SUB(a, b, c, t) \
|
# define STRICT_SUB(a, b, c, t) \
|
||||||
do { *(c) = (t)(a - b); } while (0)
|
do { *(c) = (t)(a - b); } while (0)
|
||||||
|
Reference in New Issue
Block a user