summaryrefslogtreecommitdiff
path: root/read.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2013-11-23 22:23:52 -0500
committerPaul Smith <psmith@gnu.org>2013-11-23 22:23:52 -0500
commit757849cd93a9bc361a5113e3aaafe516773aad44 (patch)
treed6acd1705fe25873b43fa7d16b736e44b6191ab7 /read.c
parent9d58570c77240fed53d1f88217877f8e778f4bb2 (diff)
downloadgunmake-757849cd93a9bc361a5113e3aaafe516773aad44.tar.gz
[SV 40361] Don't use vsnprintf(), which is an ISO C99 function.
* output.c (error, fatal, message): Take an extra argument specifying how many bytes are used by the formatted arguments. (get_buffer): New function that allocates the requested buffer size. Remove msc_vsnprintf(), vfmtconcat(), and fmtconcat() as unneeded. * makeint.h: Declare various helper macros for generating output. * *.c: Change all error(), fatal(), message() calls to use the macros, or pass the extra length argument directly.
Diffstat (limited to 'read.c')
-rw-r--r--read.c96
1 files changed, 53 insertions, 43 deletions
diff --git a/read.c b/read.c
index 2966ebe..663ffe8 100644
--- a/read.c
+++ b/read.c
@@ -368,7 +368,10 @@ eval_makefile (const char *filename, int flags)
case ENFILE:
#endif
case ENOMEM:
- fatal (reading_file, "%s", strerror (makefile_errno));
+ {
+ const char *err = strerror (makefile_errno);
+ OS (fatal, reading_file, "%s", err);
+ }
}
/* If the makefile wasn't found and it's either a makefile from
@@ -783,7 +786,7 @@ eval (struct ebuffer *ebuf, int set_default)
if (i != -2)
{
if (i == -1)
- fatal (fstart, _("invalid syntax in conditional"));
+ O (fatal, fstart, _("invalid syntax in conditional"));
ignoring = i;
continue;
@@ -912,7 +915,10 @@ eval (struct ebuffer *ebuf, int set_default)
| (noerror ? RM_DONTCARE : 0)
| (set_default ? 0 : RM_NO_DEFAULT_GOAL)));
if (!r && !noerror)
- error (fstart, "%s: %s", name, strerror (errno));
+ {
+ const char *err = strerror (errno);
+ OSS (error, fstart, "%s: %s", name, err);
+ }
}
/* Restore conditional state. */
@@ -958,7 +964,7 @@ eval (struct ebuffer *ebuf, int set_default)
/* Load the file. 0 means failure. */
r = load_file (&ebuf->floc, &name, noerror);
if (! r && ! noerror)
- fatal (&ebuf->floc, _("%s: failed to load"), name);
+ OS (fatal, &ebuf->floc, _("%s: failed to load"), name);
free_ns (files);
files = next;
@@ -984,7 +990,7 @@ eval (struct ebuffer *ebuf, int set_default)
was no preceding target, and the line might have been usable as a
variable definition. But now we know it is definitely lossage. */
if (line[0] == cmd_prefix)
- fatal (fstart, _("recipe commences before first target"));
+ O (fatal, fstart, _("recipe commences before first target"));
/* This line describes some target files. This is complicated by
the existence of target-specific variables, because we can't
@@ -1033,7 +1039,7 @@ eval (struct ebuffer *ebuf, int set_default)
{
case w_eol:
if (cmdleft != 0)
- fatal (fstart, _("missing rule before recipe"));
+ O (fatal, fstart, _("missing rule before recipe"));
/* This line contained something but turned out to be nothing
but whitespace (a comment?). */
continue;
@@ -1123,9 +1129,9 @@ eval (struct ebuffer *ebuf, int set_default)
/* There's no need to be ivory-tower about this: check for
one of the most common bugs found in makefiles... */
if (cmd_prefix == '\t' && !strneq (line, " ", 8))
- fatal (fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
+ O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
else
- fatal (fstart, _("missing separator"));
+ O (fatal, fstart, _("missing separator"));
}
/* Make the colon the end-of-string so we know where to stop
@@ -1262,13 +1268,13 @@ eval (struct ebuffer *ebuf, int set_default)
PARSEFS_NOGLOB);
++p2;
if (target == 0)
- fatal (fstart, _("missing target pattern"));
+ O (fatal, fstart, _("missing target pattern"));
else if (target->next != 0)
- fatal (fstart, _("multiple target patterns"));
+ O (fatal, fstart, _("multiple target patterns"));
pattern_percent = find_percent_cached (&target->name);
pattern = target->name;
if (pattern_percent == 0)
- fatal (fstart, _("target pattern contains no '%%'"));
+ O (fatal, fstart, _("target pattern contains no '%%'"));
free_ns (target);
}
else
@@ -1390,7 +1396,7 @@ eval (struct ebuffer *ebuf, int set_default)
#undef word1eq
if (conditionals->if_cmds)
- fatal (fstart, _("missing 'endif'"));
+ O (fatal, fstart, _("missing 'endif'"));
/* At eof, record the last rule. */
record_waiting_files ();
@@ -1429,7 +1435,7 @@ do_undefine (char *name, enum variable_origin origin, struct ebuffer *ebuf)
var = allocated_variable_expand (name);
name = next_token (var);
if (*name == '\0')
- fatal (&ebuf->floc, _("empty variable name"));
+ O (fatal, &ebuf->floc, _("empty variable name"));
p = name + strlen (name) - 1;
while (p > name && isblank ((unsigned char)*p))
--p;
@@ -1464,7 +1470,7 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
else
{
if (var.value[0] != '\0')
- error (&defstart, _("extraneous text after 'define' directive"));
+ O (error, &defstart, _("extraneous text after 'define' directive"));
/* Chop the string before the assignment token to get the name. */
var.name[var.length] = '\0';
@@ -1474,7 +1480,7 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
n = allocated_variable_expand (name);
name = next_token (n);
if (name[0] == '\0')
- fatal (&defstart, _("empty variable name"));
+ O (fatal, &defstart, _("empty variable name"));
p = name + strlen (name) - 1;
while (p > name && isblank ((unsigned char)*p))
--p;
@@ -1489,7 +1495,7 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
/* If there is nothing left to be eval'd, there's no 'endef'!! */
if (nlines < 0)
- fatal (&defstart, _("missing 'endef', unterminated 'define'"));
+ O (fatal, &defstart, _("missing 'endef', unterminated 'define'"));
ebuf->floc.lineno += nlines;
line = ebuf->buffer;
@@ -1516,8 +1522,8 @@ do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
p += 5;
remove_comments (p);
if (*(next_token (p)) != '\0')
- error (&ebuf->floc,
- _("extraneous text after 'endef' directive"));
+ O (error, &ebuf->floc,
+ _("extraneous text after 'endef' directive"));
if (--nlevels == 0)
break;
@@ -1588,16 +1594,17 @@ conditional_line (char *line, int len, const gmk_floc *flocp)
/* Found one: skip past it and any whitespace after it. */
line = next_token (line + len);
-#define EXTRANEOUS() error (flocp, _("extraneous text after '%s' directive"), cmdname)
+#define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname)
+#define EXTRACMD() OS (fatal, flocp, _("extraneous '%s'"), cmdname)
/* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
if (cmdtype == c_endif)
{
if (*line != '\0')
- EXTRANEOUS ();
+ EXTRATEXT ();
if (!conditionals->if_cmds)
- fatal (flocp, _("extraneous '%s'"), cmdname);
+ EXTRACMD ();
--conditionals->if_cmds;
@@ -1611,12 +1618,12 @@ conditional_line (char *line, int len, const gmk_floc *flocp)
const char *p;
if (!conditionals->if_cmds)
- fatal (flocp, _("extraneous '%s'"), cmdname);
+ EXTRACMD ();
o = conditionals->if_cmds - 1;
if (conditionals->seen_else[o])
- fatal (flocp, _("only one 'else' per conditional"));
+ O (fatal, flocp, _("only one 'else' per conditional"));
/* Change the state of ignorance. */
switch (conditionals->ignoring[o])
@@ -1649,7 +1656,7 @@ conditional_line (char *line, int len, const gmk_floc *flocp)
/* If it's 'else' or 'endif' or an illegal conditional, fail. */
if (word1eq ("else") || word1eq ("endif")
|| conditional_line (line, len, flocp) < 0)
- EXTRANEOUS ();
+ EXTRATEXT ();
else
{
/* conditional_line() created a new level of conditional.
@@ -1806,7 +1813,7 @@ conditional_line (char *line, int len, const gmk_floc *flocp)
*line = '\0';
line = next_token (++line);
if (*line != '\0')
- EXTRANEOUS ();
+ EXTRATEXT ();
s2 = variable_expand (s2);
conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
@@ -1891,7 +1898,7 @@ record_target_var (struct nameseq *filenames, char *defn,
current_variable_set_list = f->variables;
v = try_variable_definition (flocp, defn, origin, 1);
if (!v)
- fatal (flocp, _("Malformed target-specific variable definition"));
+ O (fatal, flocp, _("Malformed target-specific variable definition"));
current_variable_set_list = global;
}
@@ -1950,7 +1957,7 @@ record_files (struct nameseq *filenames, const char *pattern,
at this time, since they won't get snapped and we'll get core dumps.
See Savannah bug # 12124. */
if (snapped_deps)
- fatal (flocp, _("prerequisites cannot be defined in recipes"));
+ O (fatal, flocp, _("prerequisites cannot be defined in recipes"));
/* Determine if this is a pattern rule or not. */
name = filenames->name;
@@ -2008,7 +2015,7 @@ record_files (struct nameseq *filenames, const char *pattern,
unsigned int c;
if (pattern != 0)
- fatal (flocp, _("mixed implicit and static pattern rules"));
+ O (fatal, flocp, _("mixed implicit and static pattern rules"));
/* Count the targets to create an array of target names.
We already have the first one. */
@@ -2031,7 +2038,7 @@ record_files (struct nameseq *filenames, const char *pattern,
implicit_percent = find_percent_cached (&name);
if (implicit_percent == 0)
- fatal (flocp, _("mixed implicit and normal rules"));
+ O (fatal, flocp, _("mixed implicit and normal rules"));
targets[c] = name;
target_pats[c] = implicit_percent;
@@ -2083,7 +2090,8 @@ record_files (struct nameseq *filenames, const char *pattern,
'targets: target%pattern: prereq%pattern; recipe',
make sure the pattern matches this target name. */
if (pattern && !pattern_matches (pattern, pattern_percent, name))
- error (flocp, _("target '%s' doesn't match the target pattern"), name);
+ OS (error, flocp,
+ _("target '%s' doesn't match the target pattern"), name);
else if (deps)
/* If there are multiple targets, copy the chain DEPS for all but the
last one. It is not safe for the same deps to go in more than one
@@ -2097,25 +2105,26 @@ record_files (struct nameseq *filenames, const char *pattern,
if any. */
f = enter_file (strcache_add (name));
if (f->double_colon)
- fatal (flocp,
- _("target file '%s' has both : and :: entries"), f->name);
+ OS (fatal, flocp,
+ _("target file '%s' has both : and :: entries"), f->name);
/* If CMDS == F->CMDS, this target was listed in this rule
more than once. Just give a warning since this is harmless. */
if (cmds != 0 && cmds == f->cmds)
- error (flocp,
- _("target '%s' given more than once in the same rule"),
- f->name);
+ OS (error, flocp,
+ _("target '%s' given more than once in the same rule"),
+ f->name);
/* Check for two single-colon entries both with commands.
Check is_target so that we don't lose on files such as .c.o
whose commands were preinitialized. */
else if (cmds != 0 && f->cmds != 0 && f->is_target)
{
- error (&cmds->fileinfo,
+ size_t l = strlen (f->name);
+ error (&cmds->fileinfo, l,
_("warning: overriding recipe for target '%s'"),
f->name);
- error (&f->cmds->fileinfo,
+ error (&f->cmds->fileinfo, l,
_("warning: ignoring old recipe for target '%s'"),
f->name);
}
@@ -2142,8 +2151,8 @@ record_files (struct nameseq *filenames, const char *pattern,
/* Check for both : and :: rules. Check is_target so we don't lose
on default suffix rules or makefiles. */
if (f != 0 && f->is_target && !f->double_colon)
- fatal (flocp,
- _("target file '%s' has both : and :: entries"), f->name);
+ OS (fatal, flocp,
+ _("target file '%s' has both : and :: entries"), f->name);
f = enter_file (strcache_add (name));
/* If there was an existing entry and it was a double-colon entry,
@@ -2219,7 +2228,8 @@ record_files (struct nameseq *filenames, const char *pattern,
/* Reduce escaped percents. If there are any unescaped it's an error */
name = filenames->name;
if (find_percent_cached (&name))
- error (flocp, _("*** mixed implicit and normal rules: deprecated syntax"));
+ O (error, flocp,
+ _("*** mixed implicit and normal rules: deprecated syntax"));
}
}
@@ -2528,8 +2538,8 @@ readline (struct ebuffer *ebuf)
lossage strikes again! (xmkmf puts NULs in its makefiles.)
There is nothing really to be done; we synthesize a newline so
the following line doesn't appear to be part of this line. */
- error (&ebuf->floc,
- _("warning: NUL character seen; rest of line ignored"));
+ O (error, &ebuf->floc,
+ _("warning: NUL character seen; rest of line ignored"));
p[0] = '\n';
len = 1;
}
@@ -3271,7 +3281,7 @@ parse_file_seq (char **stringp, unsigned int size, int stopmap,
switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
{
case GLOB_NOSPACE:
- fatal (NILF, _("virtual memory exhausted"));
+ OUT_OF_MEM();
case 0:
/* Success. */