summaryrefslogtreecommitdiff
path: root/src/diff3.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-08-22 13:54:04 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-08-22 14:02:22 -0700
commit57e5c514dfe12ccaf6c12d2b07047bd15ee306fb (patch)
tree8d6a230d065498df8def47dcbf4cac73d880029f /src/diff3.c
parentdadc7f231f524b08a2d6497d55e702ef418c0b60 (diff)
downloaddiffutils-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 'src/diff3.c')
-rw-r--r--src/diff3.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/diff3.c b/src/diff3.c
index c67eb40..9e4ad54 100644
--- a/src/diff3.c
+++ b/src/diff3.c
@@ -1008,9 +1008,6 @@ process_diff (char const *filea,
lin i;
struct diff_block *block_list;
struct diff_block **block_list_end = &block_list;
- size_t too_many_lines = (PTRDIFF_MAX
- / MIN (sizeof *block_list->lines[1],
- sizeof *block_list->lengths[1]));
diff_limit = read_diff (filea, fileb, &diff_contents);
*buf_to_free = diff_contents;
@@ -1056,10 +1053,8 @@ process_diff (char const *filea,
if (dt != ADD)
{
lin numlines = D_NUMLINES (bptr, 0);
- if (too_many_lines <= numlines)
- xalloc_die ();
- bptr->lines[0] = xmalloc (numlines * sizeof *bptr->lines[0]);
- bptr->lengths[0] = xmalloc (numlines * sizeof *bptr->lengths[0]);
+ bptr->lines[0] = xnmalloc (numlines, sizeof *bptr->lines[0]);
+ bptr->lengths[0] = xnmalloc (numlines, sizeof *bptr->lengths[0]);
for (i = 0; i < numlines; i++)
scan_diff = scan_diff_line (scan_diff,
&(bptr->lines[0][i]),
@@ -1081,10 +1076,8 @@ process_diff (char const *filea,
if (dt != DELETE)
{
lin numlines = D_NUMLINES (bptr, 1);
- if (too_many_lines <= numlines)
- xalloc_die ();
- bptr->lines[1] = xmalloc (numlines * sizeof *bptr->lines[1]);
- bptr->lengths[1] = xmalloc (numlines * sizeof *bptr->lengths[1]);
+ bptr->lines[1] = xnmalloc (numlines, sizeof *bptr->lines[1]);
+ bptr->lengths[1] = xnmalloc (numlines, sizeof *bptr->lengths[1]);
for (i = 0; i < numlines; i++)
scan_diff = scan_diff_line (scan_diff,
&(bptr->lines[1][i]),