summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2006-03-02 08:53:45 +0000
committerphk <phk@FreeBSD.org>2006-03-02 08:53:45 +0000
commit0ef226b65a4f2734b63783c3f6c84e514c9f8ddb (patch)
tree21794befb285de1f008f2281ce158f296854bc9c /lib/libc
parentd250185c5c3ad22efff28f9d4d98f82421b118a9 (diff)
downloadFreeBSD-src-0ef226b65a4f2734b63783c3f6c84e514c9f8ddb.zip
FreeBSD-src-0ef226b65a4f2734b63783c3f6c84e514c9f8ddb.tar.gz
Fix the %Q printf extension to behave as expected
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/xprintf_quote.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/libc/stdio/xprintf_quote.c b/lib/libc/stdio/xprintf_quote.c
index bd40a16..0edcd30 100644
--- a/lib/libc/stdio/xprintf_quote.c
+++ b/lib/libc/stdio/xprintf_quote.c
@@ -50,31 +50,23 @@ int
__printf_render_quote(struct __printf_io *io, const struct printf_info *pi __unused, const void *const *arg)
{
const char *str, *p, *t, *o;
- char *q, *r;
+ char r[5];
int i, ret;
str = *((const char *const *)arg[0]);
if (str == NULL)
return (__printf_out(io, pi, "\"(null)\"", 8));
- i = 0;
if (*str == '\0')
- i++;
- else if (*str == '#')
- i++;
- else {
- for (p = str; *p; p++)
- if (isspace(*p) || *p == '\\' || *p == '"')
- i++;
- }
+ return (__printf_out(io, pi, "\"\"", 2));
+
+ for (i = 0, p = str; *p; p++)
+ if (isspace(*p) || *p == '\\' || *p == '"')
+ i++;
if (!i)
return (__printf_out(io, pi, str, strlen(str)));
- q = malloc(strlen(str) * 5);
- assert(q != NULL);
- r = q;
ret = __printf_out(io, pi, "\"", 1);
- t = str;
- for (p = str; *p; p++) {
+ for (t = p = str; *p; p++) {
o = NULL;
if (*p == '\\')
o = "\\\\";
@@ -91,14 +83,12 @@ __printf_render_quote(struct __printf_io *io, const struct printf_info *pi __unu
else if (isspace(*p)) {
sprintf(r, "\\%03o", *p);
o = r;
- r += strlen(r) + 1;
} else
continue;
- if (p != t) {
+ if (p != t)
ret += __printf_out(io, pi, t, p - t);
- t = p + 1;
- }
ret += __printf_out(io, pi, o, strlen(o));
+ t = p + 1;
}
if (p != t)
ret += __printf_out(io, pi, t, p - t);
OpenPOWER on IntegriCloud