diff options
author | Andreas Gruenbacher <agruen@gnu.org> | 2015-01-20 12:20:00 +0100 |
---|---|---|
committer | Andreas Gruenbacher <agruen@gnu.org> | 2015-01-20 12:43:57 +0100 |
commit | 0c08d7a902c6fdd49b704623a12d8d672ef18944 (patch) | |
tree | bc62d4cb9cf7d822db166feabb338ebc6361a35c | |
parent | 19285e563aa32a96672373a9bfe8a71a37bd7bfe (diff) | |
download | patch-0c08d7a902c6fdd49b704623a12d8d672ef18944.tar.gz |
Fail when out of memory in set_hunkmax()v2.7.2
src/pch.c (another_hunk): Call set_hunkmax() from here to make sure it is
called even when falling back from plan A to plan B.
(open_patch_file): No need to call set_hunkmax() anymore.
src/pch.c (set_hunkmax): Fail when out of memory. Make static.
src/pch.h: Remove set_hunkmax() prototype.
-rw-r--r-- | src/pch.c | 11 | ||||
-rw-r--r-- | src/pch.h | 1 |
2 files changed, 6 insertions, 6 deletions
@@ -158,20 +158,19 @@ open_patch_file (char const *filename) if (p_filesize != (file_offset) p_filesize) fatal ("patch file is too long"); next_intuit_at (file_pos, 1); - set_hunkmax(); } /* Make sure our dynamically realloced tables are malloced to begin with. */ -void +static void set_hunkmax (void) { if (!p_line) - p_line = (char **) malloc (hunkmax * sizeof *p_line); + p_line = (char **) xmalloc (hunkmax * sizeof *p_line); if (!p_len) - p_len = (size_t *) malloc (hunkmax * sizeof *p_len); + p_len = (size_t *) xmalloc (hunkmax * sizeof *p_len); if (!p_Char) - p_Char = malloc (hunkmax * sizeof *p_Char); + p_Char = xmalloc (hunkmax * sizeof *p_Char); } /* Enlarge the arrays containing the current hunk of patch. */ @@ -1173,6 +1172,8 @@ another_hunk (enum diff difftype, bool rev) char numbuf2[LINENUM_LENGTH_BOUND + 1]; char numbuf3[LINENUM_LENGTH_BOUND + 1]; + set_hunkmax(); + while (p_end >= 0) { if (p_end == p_efake) p_end = p_bfake; /* don't free twice */ @@ -46,7 +46,6 @@ bool pch_rename (void) _GL_ATTRIBUTE_PURE; void do_ed_script (char const *, char const *, bool *, FILE *); void open_patch_file (char const *); void re_patch (void); -void set_hunkmax (void); void pch_normalize (enum diff); XTERN struct timespec p_timestamp[2]; /* timestamps in patch headers */ |