size_t tsz;
t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1);
+ if (!t)
+ flexfatal (_("Allocation of buffer to print string failed"));
snprintf (t, tsz, fmt, s);
buf = buf_strappend (buf, t);
flex_free (t);
size_t tsz;
t = flex_alloc (tsz = strlen (fmt) + strlen (filename) + (int)(1 + log10(lineno>=0?lineno:-lineno)) + 1);
+ if (!t)
+ flexfatal (_("Allocation of buffer for line directive failed"));
snprintf (t, tsz, fmt, lineno, filename);
buf = buf_strappend (buf, t);
flex_free (t);
val = val?val:"";
str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2);
+ if (!str)
+ flexfatal (_("Allocation of buffer for m4 def failed"));
snprintf(str, strsz, fmt, def, val);
buf_append(buf, &str, 1);
size_t strsz;
str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
+ if (!str)
+ flexfatal (_("Allocation of buffer for m4 undef failed"));
snprintf(str, strsz, fmt, def);
buf_append(buf, &str, 1);
/* allocate and initialize new filter */
f = (struct filter *) flex_alloc (sizeof (struct filter));
+ if (!f)
+ flexerror (_("flex_alloc failed (f) in filter_create_ext"));
memset (f, 0, sizeof (*f));
f->filter_func = NULL;
f->extra = NULL;
f->argv =
(const char **) flex_alloc (sizeof (char *) *
(max_args + 1));
+ if (!f->argv)
+ flexerror (_("flex_alloc failed (f->argv) in filter_create_ext"));
f->argv[f->argc++] = cmd;
va_start (ap, cmd);
/* allocate and initialize new filter */
f = (struct filter *) flex_alloc (sizeof (struct filter));
+ if (!f)
+ flexerror (_("flex_alloc failed in filter_create_int"));
memset (f, 0, sizeof (*f));
f->next = NULL;
f->argc = 0;
bool filter_apply_chain (struct filter * chain)
{
int pid, pipes[2];
+ int r;
+ const int readsz = 512;
+ char *buf;
+
/* Tricky recursion, since we want to begin the chain
* at the END. Why? Because we need all the forked processes
fflush (stdout);
fflush (stderr);
+
if (pipe (pipes) == -1)
flexerror (_("pipe failed"));
else {
execvp (chain->argv[0],
(char **const) (chain->argv));
- flexfatal (_("exec failed"));
+ lerrsf_fatal ( _("exec of %s failed"),
+ chain->argv[0]);
}
exit (1);
outfilename ? outfilename : "<stdout>");
buf = (char *) flex_alloc (readsz);
+ if (!buf)
+ flexerror (_("flex_alloc failed in filter_tee_header"));
while (fgets (buf, readsz, stdin)) {
fputs (buf, to_c);
if (write_header)
fputs ("m4_undefine( [[M4_YY_IN_HEADER]])m4_dnl\n", to_h);
fflush (to_h);
- if (ferror (to_h))
- lerrsf (_("error writing output file %s"),
- (char *) chain->extra);
+ if (ferror (to_h))
+ lerrsf (_("error writing output file %s"),
+ (char *) chain->extra);
- else if (fclose (to_h))
- lerrsf (_("error closing output file %s"),
- (char *) chain->extra);
+ else if (fclose (to_h))
+ lerrsf (_("error closing output file %s"),
+ (char *) chain->extra);
}
fflush (to_c);
return 0;
buf = (char *) flex_alloc (readsz);
+ if (!buf)
+ flexerror (_("flex_alloc failed in filter_fix_linedirs"));
while (fgets (buf, readsz, stdin)) {
/* Check for #line directive. */
if (buf[0] == '#'
- && regexec (®ex_linedir, buf, 3, m, 0) == 0) {
+ && regexec (®ex_linedir, buf, 3, m, 0) == 0) {
int num;
char *fname;
size_t strsz;
str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int)(1 + log10(i)) + 2);
+ if (!str)
+ flexfatal(_("allocation of macro definition failed"));
snprintf(str, strsz, fmt, scname[i], i - 1);
buf_strappend(&tmpbuf, str);
free(str);
if(!sko_stack){
sko_sz = 1;
sko_stack = (struct sko_state*)flex_alloc(sizeof(struct sko_state)*sko_sz);
+ if (!sko_stack)
+ flexfatal(_("allocation of sko_stack failed"));
sko_len = 0;
}
if(sko_len >= sko_sz){
/* lerrsf - report an error message formatted with one string argument */
void lerrsf (msg, arg)
- const char *msg, arg[];
+ const char *msg, arg[];
{
char errmsg[MAXLINE];
- snprintf (errmsg, sizeof(errmsg), msg, arg);
+ snprintf (errmsg, sizeof(errmsg)-1, msg, arg);
+ errmsg[sizeof(errmsg)-1] = 0; /* ensure NULL termination */
flexerror (errmsg);
}
+/* lerrsf_fatal - as lerrsf, but call flexfatal */
+
+void lerrsf_fatal (msg, arg)
+ const char *msg, arg[];
+{
+ char errmsg[MAXLINE];
+
+ snprintf (errmsg, sizeof(errmsg)-1, msg, arg);
+ errmsg[sizeof(errmsg)-1] = 0; /* ensure NULL termination */
+ flexfatal (errmsg);
+}
+
+
/* line_directive_out - spit out a "#line" statement */
void line_directive_out (output_file, do_infile)
const int errbuf_sz = 200;
char * errbuf=0;
- errbuf = (char*)flex_alloc(errbuf_sz *sizeof(char));
+ errbuf = (char*)flex_alloc(errbuf_sz *sizeof(char));
+ if (!errbuf)
+ flexfatal(_("Unable to allocate buffer to report regcomp failed"));
regerror (err, preg, errbuf, errbuf_sz);
snprintf (errbuf, errbuf_sz, "regcomp failed: %s\n", errbuf);
return NULL;
len = m->rm_eo - m->rm_so;
str = (char *) flex_alloc ((len + 1) * sizeof (char));
+ if (!str)
+ flexfatal(_("Unable to allocate a copy of the match"));
strncpy (str, src + m->rm_so, len);
str[len] = 0;
return str;
{
assert(_sf_stk == NULL);
_sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32));
+ if (!_sf_stk)
+ lerrsf_fatal(_("Unable to allocate %ld of stack"),
+ (long)sizeof(scanflags_t));
_sf_stk[_sf_top_ix] = 0;
}