Commit 8a1ad756 authored by Russ Cox's avatar Russ Cox

make %Z handle embedded NULs; remove fixed-size buffer

R=r
DELTA=44  (2 added, 15 deleted, 27 changed)
OCL=18270
CL=18273
parent 2eb17d78
......@@ -1325,54 +1325,41 @@ treecopy(Node *n)
int
Zconv(Fmt *fp)
{
char *s, *se;
char *p;
char buf[500];
int c;
Rune r;
String *sp;
char *s, *se;
sp = va_arg(fp->args, String*);
if(sp == nil) {
snprint(buf, sizeof(buf), "<nil>");
goto out;
}
if(sp == nil)
return fmtstrcpy(fp, "<nil>");
s = sp->s;
se = s + sp->len;
p = buf;
loop:
c = *s++;
if(s > se)
c = 0;
switch(c) {
while(s < se) {
s += chartorune(&r, s);
switch(r) {
default:
*p++ = c;
fmtrune(fp, r);
break;
case '\0':
fmtstrcpy(fp, "\\x00");
break;
case 0:
*p = 0;
goto out;
case '\t':
*p++ = '\\';
*p++ = 't';
fmtstrcpy(fp, "\\t");
break;
case '\n':
*p++ = '\\';
*p++ = 'n';
fmtstrcpy(fp, "\\n");
break;
case '\"':
case '\\':
*p++ = '\\';
*p++ = c;
fmtrune(fp, '\\');
fmtrune(fp, r);
break;
}
goto loop;
out:
return fmtstrcpy(fp, buf);
}
return 0;
}
static char*
wnames[] =
{
......
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