ref: 34a1b1bb22e482e9a31e522e6df1b34d1673a20a
parent: e6634fbd0c3e091d6db26c4290d6b31e1e7a36e7
author: cinap_lenrek <[email protected]>
date: Sun Apr 19 00:33:07 EDT 2020
?c: fix Bconv() misusage of strncat()
--- a/sys/src/cmd/1c/list.c
+++ b/sys/src/cmd/1c/list.c
@@ -16,25 +16,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
--- a/sys/src/cmd/2c/list.c
+++ b/sys/src/cmd/2c/list.c
@@ -27,25 +27,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
--- a/sys/src/cmd/5c/list.c
+++ b/sys/src/cmd/5c/list.c
@@ -17,25 +17,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
char *extra [] = {
@@ -195,12 +189,10 @@
int
Rconv(Fmt *fp)
{
- char str[STRINGSZ];
Adr *a;
int i, v;
a = va_arg(fp->args, Adr*);
- snprint(str, sizeof str, "GOK-reglist");
switch(a->type) {
case D_CONST:
if(a->reg != NREG)
@@ -208,19 +200,14 @@
if(a->sym != S)
break;
v = a->offset;
- memset(str, 0, sizeof str);
+ fmtprint(fp, "[");
for(i=0; i<NREG; i++) {
- if(v & (1<<i)) {
- if(str[0] == 0)
- strncat(str, "[R", sizeof str - 1);
- else
- strncat(str, ",R", sizeof str - 1);
- snprint(str+strlen(str), sizeof(str)-strlen(str), "%d", i);
- }
+ if(v & (1<<i))
+ fmtprint(fp, "R%d,", i);
}
- strncat(str, "]", sizeof str - 1);
+ fmtprint(fp, "]");
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
--- a/sys/src/cmd/6c/list.c
+++ b/sys/src/cmd/6c/list.c
@@ -16,44 +16,36 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%lld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%lld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
Pconv(Fmt *fp)
{
- char str[STRINGSZ];
Prog *p;
p = va_arg(fp->args, Prog*);
if(p->as == ADATA)
- snprint(str, sizeof str, " %A %D/%d,%D",
+ return fmtprint(fp, " %A %D/%d,%D",
p->as, &p->from, p->from.scale, &p->to);
else if(p->as == ATEXT)
- snprint(str, sizeof str, " %A %D,%d,%D",
+ return fmtprint(fp, " %A %D,%d,%D",
p->as, &p->from, p->from.scale, &p->to);
else
- snprint(str, sizeof str, " %A %D,%D",
+ return fmtprint(fp, " %A %D,%D",
p->as, &p->from, &p->to);
- return fmtstrcpy(fp, str);
}
int
@@ -274,16 +266,13 @@
int
Rconv(Fmt *fp)
{
- char str[20];
int r;
r = va_arg(fp->args, int);
if(r >= D_AL && r <= D_NONE)
- snprint(str, sizeof str, "%s", regstr[r-D_AL]);
+ return fmtprint(fp, "%s", regstr[r-D_AL]);
else
- snprint(str, sizeof str, "gok(%d)", r);
-
- return fmtstrcpy(fp, str);
+ return fmtprint(fp, "gok(%d)", r);
}
int
--- a/sys/src/cmd/8c/list.c
+++ b/sys/src/cmd/8c/list.c
@@ -16,25 +16,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof(ss), "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
--- a/sys/src/cmd/kc/list.c
+++ b/sys/src/cmd/kc/list.c
@@ -16,25 +16,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
--- a/sys/src/cmd/qc/list.c
+++ b/sys/src/cmd/qc/list.c
@@ -16,25 +16,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int
--- a/sys/src/cmd/vc/list.c
+++ b/sys/src/cmd/vc/list.c
@@ -15,25 +15,19 @@
int
Bconv(Fmt *fp)
{
- char str[STRINGSZ], ss[STRINGSZ], *s;
Bits bits;
int i;
- memset(str, 0, sizeof str);
bits = va_arg(fp->args, Bits);
while(bany(&bits)) {
i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%ld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
bits.b[i/32] &= ~(1L << (i%32));
+ if(var[i].sym == S)
+ fmtprint(fp, "$%ld ", var[i].offset);
+ else
+ fmtprint(fp, "%s ", var[i].sym->name);
}
- return fmtstrcpy(fp, str);
+ return 0;
}
int