diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2014-11-30 15:47:32 +0100 |
---|---|---|
committer | Andreas Gruenbacher <agruen@linbit.com> | 2014-11-30 15:52:42 +0100 |
commit | f22e47d873ac6b7abbc31fdedc51019766ee7c86 (patch) | |
tree | 1ed56c884235f5001454a354c1f8ab21364b7b14 | |
parent | e4c6511f4660047957cd5be4e76964542e2d9447 (diff) | |
download | patch-f22e47d873ac6b7abbc31fdedc51019766ee7c86.tar.gz |
More savebuf/savestr error handling
* bootstrap.conf: use xmemdup0 module.
* src/pch.c (there_is_another_patch): Use xmemdup0 instead of savebuf when we
cannot recover from out-of-memory situations.
(intuit_diff_type): Likewise, use xstrdup instead of savestr.
(another_hunk): Handle the case when savestr returns NULL.
* src/util.c (fetchname, parse_name): Use xmemdup0 instead of savebuf when we
cannot recover from out-of-memory situations.
Bugs pointed out by Tobias Stoeckmann <tobias@stoeckmann.org>.
-rw-r--r-- | bootstrap.conf | 1 | ||||
-rw-r--r-- | src/pch.c | 12 | ||||
-rw-r--r-- | src/util.c | 10 |
3 files changed, 13 insertions, 10 deletions
diff --git a/bootstrap.conf b/bootstrap.conf index 7649539..d6074b3 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -69,6 +69,7 @@ utimens verror xalloc xlist +xmemdup0 " gnulib_tool_option_extras='--symlink --makefile-name=gnulib.mk' @@ -25,6 +25,7 @@ #include <quotearg.h> #include <util.h> #include <xalloc.h> +#include <xmemdup0.h> #undef XTERN #define XTERN #include <pch.h> @@ -291,8 +292,7 @@ there_is_another_patch (bool need_header, mode_t *file_type) t = buf + strlen (buf); if (t > buf + 1 && *(t - 1) == '\n') { - inname = savebuf (buf, t - buf); - inname[t - buf - 1] = 0; + inname = xmemdup0 (buf, t - buf - 1); inerrno = stat_file (inname, &instat); if (inerrno) { @@ -623,7 +623,7 @@ intuit_diff_type (bool need_header, mode_t *p_file_type) else { char oldc = *t; *t = '\0'; - revision = savestr (revision); + revision = xstrdup (revision); *t = oldc; } } @@ -1015,7 +1015,7 @@ intuit_diff_type (bool need_header, mode_t *p_file_type) } else { - inname = savestr(p_name[i]); + inname = xstrdup (p_name[i]); inerrno = stat_errno[i]; invc = version_controlled[i]; instat = st[i]; @@ -1255,6 +1255,8 @@ another_hunk (enum diff difftype, bool rev) s++; *s = '\0'; p_c_function = savestr (p_c_function); + if (! p_c_function) + return -1; } p_hunk_beg = p_input_line + 1; while (p_end < p_max) { @@ -1658,6 +1660,8 @@ another_hunk (enum diff difftype, bool rev) s++; *s = '\0'; p_c_function = savestr (p_c_function); + if (! p_c_function) + return -1; } if (!p_ptrn_lines) p_first++; /* do append rather than insert */ @@ -27,6 +27,7 @@ #define XTERN #include <util.h> #include <xalloc.h> +#include <xmemdup0.h> #include <getdate.h> #include "ignore-value.h" @@ -1476,8 +1477,7 @@ fetchname (char const *at, int strip_leading, char **pname, break; } } - name = savebuf (at, t - at + 1); - name[t - at] = 0; + name = xmemdup0 (at, t - at); } /* If the name is "/dev/null", ignore the name and mark the file @@ -1509,8 +1509,7 @@ fetchname (char const *at, int strip_leading, char **pname, u--; if (u != t && *(u-1) == '\r') u--; - timestr = savebuf (t, u - t + 1); - timestr[u - t] = 0; + timestr = xmemdup0 (t, u - t); } if (*t != '\n') @@ -1568,8 +1567,7 @@ parse_name (char const *s, int strip_leading, char const **endp) for (t = s; *t && ! ISSPACE ((unsigned char) *t); t++) /* do nothing*/ ; - ret = savebuf (s, t - s + 1); - ret[t - s] = 0; + ret = xmemdup0 (s, t - s); if (endp) *endp = t; } |