From 57e5c514dfe12ccaf6c12d2b07047bd15ee306fb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 22 Aug 2021 13:54:04 -0700 Subject: 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. --- lib/cmpbuf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/cmpbuf.c') 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; } -- cgit v1.2.1