acid patom() wasn't careful enough when printing. \B tends to print some junk due to buffer overflow, use %b instead of using a custom function. also be careful to use the h flag when passing shorts and cast to unsigned types when required by the flag to prevent sign extension problems. also, clean up bad formatting. Reference: /n/sources/patch/maybe/acid-builtin Date: Fri Oct 28 17:41:18 CES 2011 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/acid/builtin.c Fri Oct 28 17:37:59 2011 +++ /sys/src/cmd/acid/builtin.c Fri Oct 28 17:37:58 2011 @@ -40,8 +40,8 @@ void include(Node*, Node*); void regexp(Node*, Node*); void dosysr1(Node*, Node*); -void fmtof(Node*, Node*) ; -void dofmtsize(Node*, Node*) ; +void fmtof(Node*, Node*); +void dofmtsize(Node*, Node*); typedef struct Btab Btab; struct Btab @@ -861,7 +861,7 @@ } } -void +void flatten(Node **av, Node *n) { if(n == 0) @@ -969,7 +969,6 @@ void patom(char type, Store *res) { - int i; char buf[512]; extern char *typenames[]; @@ -984,20 +983,13 @@ Bprint(bout, "%3c", (int)res->ival); break; case 'r': - Bprint(bout, "%C", (int)res->ival); + Bprint(bout, "%C", (uint)res->ival); break; case 'B': - memset(buf, '0', 34); - buf[1] = 'b'; - for(i = 0; i < 32; i++) { - if(res->ival & (1<ival); break; case 'b': - Bprint(bout, "%.2x", (int)res->ival&0xff); + Bprint(bout, "%.2x", (uint)res->ival&0xff); break; case 'X': Bprint(bout, "%.8lux", (ulong)res->ival); @@ -1009,10 +1001,10 @@ Bprint(bout, "%d", (int)res->ival); break; case 'd': - Bprint(bout, "%d", (ushort)res->ival); + Bprint(bout, "%hd", (short)res->ival); break; case 'u': - Bprint(bout, "%d", (int)res->ival&0xffff); + Bprint(bout, "%hud", (uint)res->ival&0xffff); break; case 'U': Bprint(bout, "%lud", (ulong)res->ival); @@ -1030,13 +1022,13 @@ Bprint(bout, "%.16llux", res->ival); break; case 'o': - Bprint(bout, "0%.11uo", (int)res->ival&0xffff); + Bprint(bout, "0%.11uo", (uint)res->ival&0xffff); break; case 'O': Bprint(bout, "0%.6uo", (int)res->ival); break; case 'q': - Bprint(bout, "0%.11o", (short)(res->ival&0xffff)); + Bprint(bout, "0%.11ho", (short)(res->ival&0xffff)); break; case 'Q': Bprint(bout, "0%.6o", (int)res->ival); @@ -1270,7 +1262,8 @@ r->ival = strtol(p+1, 0, 0); } -void fmtof(Node *r, Node *args) +void +fmtof(Node *r, Node *args) { Node *av[Maxarg]; Node res; @@ -1280,36 +1273,36 @@ if(na < 1) error("fmtof(obj): no argument"); if(na > 1) - error("fmtof(obj): too many arguments") ; + error("fmtof(obj): too many arguments"); expr(av[0], &res); r->op = OCONST; - r->type = TINT ; - r->ival = res.fmt ; + r->type = TINT; + r->ival = res.fmt; r->fmt = 'c'; } -void dofmtsize(Node *r, Node *args) +void +dofmtsize(Node *r, Node *args) { - Node *av[Maxarg]; - Node res; - Store * s ; - Value v ; + Node *av[Maxarg], res; + Store *s; + Value v; na = 0; flatten(av, args); if(na < 1) error("fmtsize(obj): no argument"); if(na > 1) - error("fmtsize(obj): too many arguments") ; + error("fmtsize(obj): too many arguments"); expr(av[0], &res); - v.type = res.type ; - s = &v.Store ; - *s = res ; + v.type = res.type; + s = &v.Store; + *s = res; r->op = OCONST; - r->type = TINT ; - r->ival = fmtsize(&v) ; + r->type = TINT; + r->ival = fmtsize(&v); r->fmt = 'D'; }