diff options
-rw-r--r-- | shared/nm-std-aux/nm-std-aux.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h index 762f104be3..b181f93821 100644 --- a/shared/nm-std-aux/nm-std-aux.h +++ b/shared/nm-std-aux/nm-std-aux.h @@ -189,6 +189,19 @@ typedef uint64_t _nm_bitwise nm_be64_t; /*****************************************************************************/ +static inline uint32_t +nm_add_u32_clamped(uint32_t a, uint32_t b) +{ + uint32_t c; + + /* returns the sum of a+b, or UINT32_MAX if the result would overflow. */ + + c = a + b; + if (c < a) + return UINT32_MAX; + return c; +} + /* glib's MIN()/MAX() macros don't have function-like behavior, in that they evaluate * the argument possibly twice. * |