Skip to content
Snippets Groups Projects
Unverified Commit 759517f8 authored by Simon McVittie's avatar Simon McVittie Committed by GitHub
Browse files

Merge pull request #663 from smcv/builtin-overflow

utils: Add a fallback version of xadd, xmul for ancient gcc
parents c1bfc720 bcd96143
No related branches found
No related tags found
1 merge request!729Optionally emit priority level markers on bubblewrap messages
......@@ -959,10 +959,17 @@ mount_strerror (int errsv)
static size_t
xadd (size_t a, size_t b)
{
#if defined(__GNUC__) && __GNUC__ >= 5
size_t result;
if (__builtin_add_overflow (a, b, &result))
die_oom ();
return result;
#else
if (a > SIZE_MAX - b)
die_oom ();
return a + b;
#endif
}
/*
......@@ -972,10 +979,17 @@ xadd (size_t a, size_t b)
static size_t
xmul (size_t a, size_t b)
{
#if defined(__GNUC__) && __GNUC__ >= 5
size_t result;
if (__builtin_mul_overflow (a, b, &result))
die_oom ();
return result;
#else
if (b != 0 && a > SIZE_MAX / b)
die_oom ();
return a * b;
#endif
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment