summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@gnu.org>2015-01-20 12:20:00 +0100
committerAndreas Gruenbacher <agruen@gnu.org>2015-01-20 12:43:57 +0100
commit0c08d7a902c6fdd49b704623a12d8d672ef18944 (patch)
treebc62d4cb9cf7d822db166feabb338ebc6361a35c
parent19285e563aa32a96672373a9bfe8a71a37bd7bfe (diff)
downloadpatch-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.c11
-rw-r--r--src/pch.h1
2 files changed, 6 insertions, 6 deletions
diff --git a/src/pch.c b/src/pch.c
index 145c4ef..33facd9 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -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 */
diff --git a/src/pch.h b/src/pch.h
index 0c7ff62..9565ac4 100644
--- a/src/pch.h
+++ b/src/pch.h
@@ -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 */