diff options
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | Makefile.in | 4 | ||||
| -rw-r--r-- | pch.c | 24 | ||||
| -rwxr-xr-x | tests/no-newline-triggers-assert | 37 | ||||
| -rw-r--r-- | util.c | 4 |
5 files changed, 63 insertions, 12 deletions
@@ -36,6 +36,12 @@ * tests/preserve-c-function-names: New test case. * Makefile.in (TESTS): Add test case. + * util.c (savebuf): Return NULL if size == 0. + * pch.c (another_hunk): Check size for size != 0 before checking + savebuf()'s return value. + * tests/no-newline-triggers-assert: New test case. + * Makefile.in (TESTS): Add test case. + 2009-03-19 Andreas Gruenbacher <agruen@suse.de> Imported from Paul Eggert's working directory: diff --git a/Makefile.in b/Makefile.in index 595289a..fd5124f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -88,8 +88,8 @@ HDRS = argmatch.h backupfile.h common.h dirname.h \ MISC = AUTHORS COPYING ChangeLog INSTALL Makefile.in NEWS README VERSION \ aclocal.m4 config.hin configure configure.ac install-sh \ mkinstalldirs patch.man stdbool_.h timespec.h -TESTS = tests/crlf-handling tests/preserve-c-function-names \ - tests/remember-backup-files +TESTS = tests/no-newline-triggers-assert tests/preserve-c-function-names \ + tests/remember-backup-files tests/crlf-handling DISTFILES = $(MISC) $(SRCS) $(HDRS) $(M4FILES) $(TESTS) \ pc/chdirsaf.c pc/djgpp/config.sed pc/djgpp/configure.bat \ pc/djgpp/configure.sed pc/djgpp/README @@ -1094,10 +1094,11 @@ another_hunk (enum diff difftype, bool rev) && p_end == (repl_beginning ? p_max : p_ptrn_lines) && incomplete_line ()); p_len[p_end] = chars_read; - if (! (p_line[p_end] = savebuf (s, chars_read))) { + p_line[p_end] = savebuf (s, chars_read); + if (chars_read && ! p_line[p_end]) { p_end--; return -1; - } + } context = 0; break; case '\t': case '\n': /* assume spaces got eaten */ @@ -1116,7 +1117,8 @@ another_hunk (enum diff difftype, bool rev) && p_end == (repl_beginning ? p_max : p_ptrn_lines) && incomplete_line ()); p_len[p_end] = chars_read; - if (! (p_line[p_end] = savebuf (buf, chars_read))) { + p_line[p_end] = savebuf (buf, chars_read); + if (chars_read && ! p_line[p_end]) { p_end--; return -1; } @@ -1156,7 +1158,8 @@ another_hunk (enum diff difftype, bool rev) && p_end == (repl_beginning ? p_max : p_ptrn_lines) && incomplete_line ()); p_len[p_end] = chars_read; - if (! (p_line[p_end] = savebuf (buf + 2, chars_read))) { + p_line[p_end] = savebuf (buf + 2, chars_read); + if (chars_read && ! p_line[p_end]) { p_end--; return -1; } @@ -1357,12 +1360,13 @@ another_hunk (enum diff difftype, bool rev) ch = *buf; s = savebuf (buf+1, --chars_read); } - if (!s) { + if (chars_read && ! s) + { while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc-1; return -1; - } + } switch (ch) { case '-': if (fillsrc > p_ptrn_lines) { @@ -1392,7 +1396,7 @@ another_hunk (enum diff difftype, bool rev) p_line[fillsrc] = s; p_len[fillsrc++] = chars_read; s = savebuf (s, chars_read); - if (!s) { + if (chars_read && ! s) { while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc-1; @@ -1488,7 +1492,8 @@ another_hunk (enum diff difftype, bool rev) format_linenum (numbuf0, p_input_line)); chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ()); p_len[i] = chars_read; - if (! (p_line[i] = savebuf (buf + 2, chars_read))) { + p_line[i] = savebuf (buf + 2, chars_read); + if (chars_read && ! p_line[i]) { p_end = i-1; return -1; } @@ -1532,7 +1537,8 @@ another_hunk (enum diff difftype, bool rev) format_linenum (numbuf0, p_input_line)); chars_read -= 2 + (i == p_end && incomplete_line ()); p_len[i] = chars_read; - if (! (p_line[i] = savebuf (buf + 2, chars_read))) { + p_line[i] = savebuf (buf + 2, chars_read); + if (chars_read && ! p_line[i]) { p_end = i-1; return -1; } diff --git a/tests/no-newline-triggers-assert b/tests/no-newline-triggers-assert new file mode 100755 index 0000000..72e9464 --- /dev/null +++ b/tests/no-newline-triggers-assert @@ -0,0 +1,37 @@ +#! /bin/bash + +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# Copying and distribution of this file, with or without modification, +# in any medium, are permitted without royalty provided the copyright +# notice and this notice are preserved. + +# Regression test for Assertion `s && size' failed in savebuf + +. $srcdir/test-lib.sh + +require_cat +require_diff +use_local_patch +use_tmpdir + +# ============================================================== + +echo one > f + +cat > f.diff <<EOF +--- f ++++ f +@@ -1,2 +1,2 @@ +-1 ++1a + +\ No newline at end of file +EOF + +echo 1 > f + +check 'patch -p0 < f.diff' <<EOF +patching file f +Hunk #1 succeeded at 1 with fuzz 1. +EOF @@ -514,7 +514,9 @@ savebuf (register char const *s, register size_t size) { register char *rv; - assert (s && size); + if (! size) + return NULL; + rv = malloc (size); if (! rv) |
