summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-09-05 13:11:31 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-09-05 13:11:31 +0200
commit6774834becb534996452fc1032e3950fec92dcd7 (patch)
treec0c2a94171488609fe7cfa951b9c3d78da97e9b9
parentf13eeffe1cfae77f6f626ad7437f1d400722d24f (diff)
downloadmupdf-6774834becb534996452fc1032e3950fec92dcd7.tar.xz
Use 3-digit octal escapes in strings.
Octal escapes in strings that are followed by a digit must use three digits, with leading zeros if needed, so that they can be unambiguously parsed.
-rw-r--r--fitz/obj_print.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/fitz/obj_print.c b/fitz/obj_print.c
index d53d888a..30b34d95 100644
--- a/fitz/obj_print.c
+++ b/fitz/obj_print.c
@@ -100,10 +100,10 @@ static void fmt_str(struct fmt *fmt, fz_obj *obj)
fmt_puts(fmt, "\\(");
else if (c == ')')
fmt_puts(fmt, "\\)");
- else if (c < 32 || c > 126) {
+ else if (c < 32 || c >= 127) {
char buf[16];
fmt_putc(fmt, '\\');
- sprintf(buf, "%o", c);
+ sprintf(buf, "%03o", c);
fmt_puts(fmt, buf);
}
else
@@ -139,7 +139,7 @@ static void fmt_name(struct fmt *fmt, fz_obj *obj)
for (i = 0; s[i]; i++)
{
if (isdelim(s[i]) || iswhite(s[i]) ||
- s[i] == '#' || s[i] < 32 || s[i] > 127)
+ s[i] == '#' || s[i] < 32 || s[i] >= 127)
{
fmt_putc(fmt, '#');
c = (s[i] >> 4) & 0xf;
@@ -255,11 +255,7 @@ static void fmt_obj(struct fmt *fmt, fz_obj *obj)
c = (unsigned char)str[i];
if (strchr("()\\\n\r\t\b\f", c))
added ++;
- else if (c < 8)
- added ++;
- else if (c < 32)
- added += 2;
- else if (c >= 127)
+ else if (c < 32 || c >= 127)
added += 3;
}
if (added < len)