Commit 6e1ad041 authored by Russ Cox's avatar Russ Cox

avoid strncat in formatters.

the n argument to strncat is the maximum
number of bytes to read from the src,
not the total size of the destination.

R=ken
OCL=31871
CL=31875
parent 940e381b
...@@ -877,54 +877,34 @@ Econv(Fmt *fp) ...@@ -877,54 +877,34 @@ Econv(Fmt *fp)
int int
Jconv(Fmt *fp) Jconv(Fmt *fp)
{ {
char buf[500], buf1[100];
Node *n; Node *n;
n = va_arg(fp->args, Node*); n = va_arg(fp->args, Node*);
strcpy(buf, ""); if(n->ullman != 0)
fmtprint(fp, " u(%d)", n->ullman);
if(n->ullman != 0) {
snprint(buf1, sizeof(buf1), " u(%d)", n->ullman);
strncat(buf, buf1, sizeof(buf));
}
if(n->addable != 0) { if(n->addable != 0)
snprint(buf1, sizeof(buf1), " a(%d)", n->addable); fmtprint(fp, " a(%d)", n->addable);
strncat(buf, buf1, sizeof(buf));
}
if(n->vargen != 0) { if(n->vargen != 0)
snprint(buf1, sizeof(buf1), " g(%ld)", n->vargen); fmtprint(fp, " g(%ld)", n->vargen);
strncat(buf, buf1, sizeof(buf));
}
if(n->lineno != 0) {
snprint(buf1, sizeof(buf1), " l(%ld)", n->lineno);
strncat(buf, buf1, sizeof(buf));
}
if(n->xoffset != 0) { if(n->lineno != 0)
snprint(buf1, sizeof(buf1), " x(%lld)", n->xoffset); fmtprint(fp, " l(%ld)", n->lineno);
strncat(buf, buf1, sizeof(buf));
}
if(n->class != 0) { if(n->xoffset != 0)
snprint(buf1, sizeof(buf1), " class(%d)", n->class); fmtprint(fp, " x(%lld)", n->xoffset);
strncat(buf, buf1, sizeof(buf));
}
if(n->colas != 0) { if(n->class != 0)
snprint(buf1, sizeof(buf1), " colas(%d)", n->colas); fmtprint(fp, " class(%d)", n->class);
strncat(buf, buf1, sizeof(buf));
}
if(n->funcdepth != 0) { if(n->colas != 0)
snprint(buf1, sizeof(buf1), " f(%d)", n->funcdepth); fmtprint(fp, " colas(%d)", n->colas);
strncat(buf, buf1, sizeof(buf));
}
if(n->funcdepth != 0)
fmtprint(fp, " f(%d)", n->funcdepth);
return fmtstrcpy(fp, buf); return 0;
} }
int int
...@@ -1165,7 +1145,6 @@ Tpretty(Fmt *fp, Type *t) ...@@ -1165,7 +1145,6 @@ Tpretty(Fmt *fp, Type *t)
int int
Tconv(Fmt *fp) Tconv(Fmt *fp)
{ {
char buf[500], buf1[500];
Type *t, *t1; Type *t, *t1;
int r, et, sharp, minus; int r, et, sharp, minus;
...@@ -1179,7 +1158,7 @@ Tconv(Fmt *fp) ...@@ -1179,7 +1158,7 @@ Tconv(Fmt *fp)
t->trecur++; t->trecur++;
if(t->trecur > 5) { if(t->trecur > 5) {
strncat(buf, "...", sizeof(buf)); fmtprint(fp, "...");
goto out; goto out;
} }
...@@ -1200,112 +1179,98 @@ Tconv(Fmt *fp) ...@@ -1200,112 +1179,98 @@ Tconv(Fmt *fp)
} }
et = t->etype; et = t->etype;
snprint(buf, sizeof buf, "%E ", et); fmtprint(fp, "%E ", et);
if(t->sym != S) { if(t->sym != S)
snprint(buf1, sizeof(buf1), "<%S>", t->sym); fmtprint(fp, "<%S>", t->sym);
strncat(buf, buf1, sizeof(buf));
}
switch(et) { switch(et) {
default: default:
if(t->type != T) { if(t->type != T)
snprint(buf1, sizeof(buf1), " %T", t->type); fmtprint(fp, " %T", t->type);
strncat(buf, buf1, sizeof(buf));
}
break; break;
case TFIELD: case TFIELD:
snprint(buf1, sizeof(buf1), "%T", t->type); fmtprint(fp, "%T", t->type);
strncat(buf, buf1, sizeof(buf));
break; break;
case TFUNC: case TFUNC:
if(fp->flags & FmtLong) if(fp->flags & FmtLong)
snprint(buf1, sizeof(buf1), "%d%d%d(%lT,%lT)%lT", fmtprint(fp, "%d%d%d(%lT,%lT)%lT",
t->thistuple, t->intuple, t->outtuple, t->thistuple, t->intuple, t->outtuple,
t->type, t->type->down->down, t->type->down); t->type, t->type->down->down, t->type->down);
else else
snprint(buf1, sizeof(buf1), "%d%d%d(%T,%T)%T", fmtprint(fp, "%d%d%d(%T,%T)%T",
t->thistuple, t->intuple, t->outtuple, t->thistuple, t->intuple, t->outtuple,
t->type, t->type->down->down, t->type->down); t->type, t->type->down->down, t->type->down);
strncat(buf, buf1, sizeof(buf));
break; break;
case TINTER: case TINTER:
strncat(buf, "{", sizeof(buf)); fmtprint(fp, "{");
if(fp->flags & FmtLong) { if(fp->flags & FmtLong)
for(t1=t->type; t1!=T; t1=t1->down) { for(t1=t->type; t1!=T; t1=t1->down)
snprint(buf1, sizeof(buf1), "%lT;", t1); fmtprint(fp, "%lT;", t1);
strncat(buf, buf1, sizeof(buf)); fmtprint(fp, "}");
}
}
strncat(buf, "}", sizeof(buf));
break; break;
case TSTRUCT: case TSTRUCT:
strncat(buf, "{", sizeof(buf)); fmtprint(fp, "{");
if(fp->flags & FmtLong) { if(fp->flags & FmtLong)
for(t1=t->type; t1!=T; t1=t1->down) { for(t1=t->type; t1!=T; t1=t1->down)
snprint(buf1, sizeof(buf1), "%lT;", t1); fmtprint(fp, "%lT;", t1);
strncat(buf, buf1, sizeof(buf)); fmtprint(fp, "}");
}
}
strncat(buf, "}", sizeof(buf));
break; break;
case TMAP: case TMAP:
snprint(buf, sizeof(buf), "[%T]%T", t->down, t->type); fmtprint(fp, "[%T]%T", t->down, t->type);
break; break;
case TARRAY: case TARRAY:
if(t->bound >= 0) if(t->bound >= 0)
snprint(buf1, sizeof(buf1), "[%ld]%T", t->bound, t->type); fmtprint(fp, "[%ld]%T", t->bound, t->type);
else else
snprint(buf1, sizeof(buf1), "[]%T", t->type); fmtprint(fp, "[]%T", t->type);
strncat(buf, buf1, sizeof(buf));
break; break;
case TPTR32: case TPTR32:
case TPTR64: case TPTR64:
snprint(buf1, sizeof(buf1), "%T", t->type); fmtprint(fp, "%T", t->type);
strncat(buf, buf1, sizeof(buf));
break; break;
} }
out: out:
t->trecur--; t->trecur--;
return fmtstrcpy(fp, buf); return 0;
} }
int int
Nconv(Fmt *fp) Nconv(Fmt *fp)
{ {
char buf[500], buf1[500]; char buf1[500];
Node *n; Node *n;
n = va_arg(fp->args, Node*); n = va_arg(fp->args, Node*);
if(n == N) { if(n == N) {
snprint(buf, sizeof(buf), "<N>"); fmtprint(fp, "<N>");
goto out; goto out;
} }
switch(n->op) { switch(n->op) {
default: default:
snprint(buf, sizeof(buf), "%O%J", n->op, n); fmtprint(fp, "%O%J", n->op, n);
break; break;
case ONAME: case ONAME:
case ONONAME: case ONONAME:
if(n->sym == S) { if(n->sym == S) {
snprint(buf, sizeof(buf), "%O%J", n->op, n); fmtprint(fp, "%O%J", n->op, n);
break; break;
} }
snprint(buf, sizeof(buf), "%O-%S G%ld%J", n->op, fmtprint(fp, "%O-%S G%ld%J", n->op,
n->sym, n->sym->vargen, n); n->sym, n->sym->vargen, n);
goto ptyp; goto ptyp;
case OREGISTER: case OREGISTER:
snprint(buf, sizeof(buf), "%O-%R%J", n->op, n->val.u.reg, n); fmtprint(fp, "%O-%R%J", n->op, n->val.u.reg, n);
break; break;
case OLITERAL: case OLITERAL:
...@@ -1329,30 +1294,26 @@ Nconv(Fmt *fp) ...@@ -1329,30 +1294,26 @@ Nconv(Fmt *fp)
snprint(buf1, sizeof(buf1), "N"); snprint(buf1, sizeof(buf1), "N");
break; break;
} }
snprint(buf, sizeof(buf), "%O-%s%J", n->op, buf1, n); fmtprint(fp, "%O-%s%J", n->op, buf1, n);
break; break;
case OASOP: case OASOP:
snprint(buf, sizeof(buf), "%O-%O%J", n->op, n->etype, n); fmtprint(fp, "%O-%O%J", n->op, n->etype, n);
break; break;
case OTYPE: case OTYPE:
snprint(buf, sizeof(buf), "%O %T", n->op, n->type); fmtprint(fp, "%O %T", n->op, n->type);
break; break;
} }
if(n->sym != S) { if(n->sym != S)
snprint(buf1, sizeof(buf1), " %S G%ld", n->sym, n->sym->vargen); fmtprint(fp, " %S G%ld", n->sym, n->sym->vargen);
strncat(buf, buf1, sizeof(buf));
}
ptyp: ptyp:
if(n->type != T) { if(n->type != T)
snprint(buf1, sizeof(buf1), " %T", n->type); fmtprint(fp, " %T", n->type);
strncat(buf, buf1, sizeof(buf));
}
out: out:
return fmtstrcpy(fp, buf); return 0;
} }
Node* Node*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment