mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-22 10:48:02 +00:00
bspatch: use C23 overflow checking math now that it is available
Reviewed by: des Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41771
This commit is contained in:
parent
5f62584a9a
commit
ee12faa062
|
@ -36,6 +36,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <stdckdint.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -64,15 +65,8 @@ add_off_t(off_t a, off_t b)
|
|||
{
|
||||
off_t result;
|
||||
|
||||
#if __GNUC__ >= 5 || \
|
||||
(defined(__has_builtin) && __has_builtin(__builtin_add_overflow))
|
||||
if (__builtin_add_overflow(a, b, &result))
|
||||
if (ckd_add(&result, a, b))
|
||||
errx(1, "Corrupt patch");
|
||||
#else
|
||||
if ((b > 0 && a > OFF_MAX - b) || (b < 0 && a < OFF_MIN - b))
|
||||
errx(1, "Corrupt patch");
|
||||
result = a + b;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue