mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-19 13:40:43 +02:00
shared: add nm_add_u32_clamped() helper
This commit is contained in:
parent
c3fe895ebc
commit
b38075b751
1 changed files with 13 additions and 0 deletions
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue