diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-08-22 13:54:04 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-08-22 14:02:22 -0700 |
commit | 57e5c514dfe12ccaf6c12d2b07047bd15ee306fb (patch) | |
tree | 8d6a230d065498df8def47dcbf4cac73d880029f /lib/cmpbuf.c | |
parent | dadc7f231f524b08a2d6497d55e702ef418c0b60 (diff) | |
download | diffutils-57e5c514dfe12ccaf6c12d2b07047bd15ee306fb.tar.gz |
maint: refactor integer overflow checking
Rely on more-modern Gnulib capabilities instead of doing
integer overflow checking by hand, in some cases.
* lib/cmpbuf.c (buffer_lcm):
* src/io.c (slurp, find_identical_ends):
Use INT_ADD_WRAPV and INT_MULTIPLY_WRAPV rather than checking
overflow by hand.
* src/diff3.c (process_diff):
* src/dir.c (dir_read):
* src/io.c (find_identical_ends, read_files):
Use xnmalloc rather than checking overflow by hand.
(read_files): Rely on xcalloc to do overflow checking.
Diffstat (limited to 'lib/cmpbuf.c')
-rw-r--r-- | lib/cmpbuf.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/lib/cmpbuf.c b/lib/cmpbuf.c index 7cee45a..f7c34e2 100644 --- a/lib/cmpbuf.c +++ b/lib/cmpbuf.c @@ -104,6 +104,5 @@ buffer_lcm (size_t a, size_t b, size_t lcm_max) /* Yield a if there is an overflow. */ q = a / n; - lcm = q * b; - return lcm <= lcm_max && lcm / b == q ? lcm : a; + return !INT_MULTIPLY_WRAPV (q, b, &lcm) && lcm <= lcm_max ? lcm : a; } |