mirror of
https://https.git.savannah.gnu.org/git/patch.git
synced 2026-01-27 01:44:34 +00:00
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>.
This commit is contained in:
parent
e4c6511f46
commit
f22e47d873
@ -69,6 +69,7 @@ utimens
|
||||
verror
|
||||
xalloc
|
||||
xlist
|
||||
xmemdup0
|
||||
"
|
||||
|
||||
gnulib_tool_option_extras='--symlink --makefile-name=gnulib.mk'
|
||||
|
||||
12
src/pch.c
12
src/pch.c
@ -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 */
|
||||
|
||||
10
src/util.c
10
src/util.c
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user