char *fn = current_long_filename ?
current_long_filename : current_filename;
char *b, *d;
+ size_t len = 50 + strlen(fn);
- b = getmem(50 + strlen(fn));
+ b = getmem(len);
if (flags & GCC_LINE_NUM) {
- sprintf(b, "# %ld \"%s\"\n", ls->line, fn);
+ snprintf(b, len, "# %ld \"%s\"\n", ls->line, fn);
} else {
- sprintf(b, "#line %ld \"%s\"\n", ls->line, fn);
+ snprintf(b, len, "#line %ld \"%s\"\n", ls->line, fn);
}
for (d = b; *d; d ++) put_char(ls, (unsigned char)(*d));
freemem(b);
string_fname = 1;
} else if (left_angle(tf2.t[x].type) && right_angle(tf2.t[y].type)) {
int i, j;
+ size_t len;
if (ls->flags & WARN_ANNOYING) warning(l, "reconstruction "
"of <foo> in #include");
for (j = 0, i = x; i <= y; i ++) if (!ttWHI(tf2.t[i].type))
j += strlen(tname(tf2.t[i]));
- fname = getmem(j + 1);
+ len = j + 1;
+ fname = getmem(len);
for (j = 0, i = x; i <= y; i ++) {
if (ttWHI(tf2.t[i].type)) continue;
- strcpy(fname + j, tname(tf2.t[i]));
+ strlcpy(fname + j, tname(tf2.t[i]), len - j);
j += strlen(tname(tf2.t[i]));
}
*(fname + j - 1) = 0;
*/
static char *stringify(struct token_fifo *tf)
{
- size_t tlen;
+ size_t tlen, len;
size_t i;
char *x, *y;
if (tf->t[i].type < CPPERR && tf->t[i].type != OPT_NONE)
tlen += strlen(token_name(tf->t + i));
if (tlen == 0) return sdup("\"\"");
- x = getmem(tlen + 1);
+ len = tlen + 1;
+ x = getmem(len);
for (tlen = 0, i = 0; i < tf->nt; i ++) {
if (tf->t[i].type >= CPPERR || tf->t[i].type == OPT_NONE)
continue;
- strcpy(x + tlen, token_name(tf->t + i));
+ strlcpy(x + tlen, token_name(tf->t + i), len - tlen);
tlen += strlen(token_name(tf->t + i));
}
/* no need to add a trailing 0: strcpy() did that (and the string
case MAC_LINE:
t.type = NUMBER;
t.line = l;
- sprintf(buf, "%ld", l);
+ snprintf(buf, sizeof(buf), "%ld", l);
t.name = buf;
print_space(ls);
print_token(ls, &t, 0);