Commit bb3269fb authored by Ken Thompson's avatar Ken Thompson

snprints for safety

R=r
OCL=15311
CL=15311
parent c1ad0509
...@@ -73,7 +73,7 @@ Pconv(Fmt *fp) ...@@ -73,7 +73,7 @@ Pconv(Fmt *fp)
int int
Dconv(Fmt *fp) Dconv(Fmt *fp)
{ {
char str[40], s[20]; char str[100], s[100];
Addr *a; Addr *a;
int i; int i;
uint32 d1, d2; uint32 d1, d2;
...@@ -82,18 +82,18 @@ Dconv(Fmt *fp) ...@@ -82,18 +82,18 @@ Dconv(Fmt *fp)
i = a->type; i = a->type;
if(i >= D_INDIR) { if(i >= D_INDIR) {
if(a->offset) if(a->offset)
sprint(str, "%lld(%R)", a->offset, i-D_INDIR); snprint(str, sizeof(str), "%lld(%R)", a->offset, i-D_INDIR);
else else
sprint(str, "(%R)", i-D_INDIR); snprint(str, sizeof(str), "(%R)", i-D_INDIR);
goto brk; goto brk;
} }
switch(i) { switch(i) {
default: default:
if(a->offset) if(a->offset)
sprint(str, "$%lld,%R", a->offset, i); snprint(str, sizeof(str), "$%lld,%R", a->offset, i);
else else
sprint(str, "%R", i); snprint(str, sizeof(str), "%R", i);
break; break;
case D_NONE: case D_NONE:
...@@ -105,50 +105,50 @@ Dconv(Fmt *fp) ...@@ -105,50 +105,50 @@ Dconv(Fmt *fp)
break; break;
case D_EXTERN: case D_EXTERN:
sprint(str, "%S+%lld(SB)", a->sym, a->offset); snprint(str, sizeof(str), "%S+%lld(SB)", a->sym, a->offset);
break; break;
case D_STATIC: case D_STATIC:
sprint(str, "%S<>+%lld(SB)", a->sym, a->offset); snprint(str, sizeof(str), "%S<>+%lld(SB)", a->sym, a->offset);
break; break;
case D_AUTO: case D_AUTO:
sprint(str, "%S+%lld(SP)", a->sym, a->offset); snprint(str, sizeof(str), "%S+%lld(SP)", a->sym, a->offset);
break; break;
case D_PARAM: case D_PARAM:
sprint(str, "%S+%lld(FP)", a->sym, a->offset); snprint(str, sizeof(str), "%S+%lld(FP)", a->sym, a->offset);
break; break;
case D_CONST: case D_CONST:
if(fp->flags & FmtLong) { if(fp->flags & FmtLong) {
d1 = a->offset & 0xffffffffLL; d1 = a->offset & 0xffffffffLL;
d2 = (a->offset>>32) & 0xffffffffLL; d2 = (a->offset>>32) & 0xffffffffLL;
sprint(str, "$%lud-%lud", d1, d2); snprint(str, sizeof(str), "$%lud-%lud", d1, d2);
break; break;
} }
sprint(str, "$%lld", a->offset); snprint(str, sizeof(str), "$%lld", a->offset);
break; break;
case D_FCONST: case D_FCONST:
sprint(str, "$(%.17e)", a->dval); snprint(str, sizeof(str), "$(%.17e)", a->dval);
break; break;
case D_SCONST: case D_SCONST:
sprint(str, "$\"%Y\"", a->sval); snprint(str, sizeof(str), "$\"%Y\"", a->sval);
break; break;
case D_ADDR: case D_ADDR:
a->type = a->index; a->type = a->index;
a->index = D_NONE; a->index = D_NONE;
sprint(str, "$%D", a); snprint(str, sizeof(str), "$%D", a);
a->index = a->type; a->index = a->type;
a->type = D_ADDR; a->type = D_ADDR;
goto conv; goto conv;
} }
brk: brk:
if(a->index != D_NONE) { if(a->index != D_NONE) {
sprint(s, "(%R*%d)", (int)a->index, (int)a->scale); snprint(s, sizeof(s), "(%R*%d)", (int)a->index, (int)a->scale);
strcat(str, s); strcat(str, s);
} }
conv: conv:
......
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