[cairo-commit] util/cairo-trace

Chris Wilson ickle at kemper.freedesktop.org
Thu Jan 7 03:59:14 PST 2010


 util/cairo-trace/trace.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

New commits:
commit 41a24d822ac094f0841ba0c92ca86448ad062def
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jan 7 11:58:01 2010 +0000

    trace: Correctly encode octal values.
    
    How embarrassing.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index 3f7ae26..41481a5 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -1745,6 +1745,15 @@ DONE:
 }
 
 static void
+to_octal (int value, char *buf, size_t size)
+{
+    do {
+	buf[--size] = '0' + (value & 7);
+	value >>= 3;
+    } while (size);
+}
+
+static void
 _emit_string_literal (const char *utf8, int len)
 {
     char c;
@@ -1787,13 +1796,11 @@ ESCAPED_CHAR:
 	    if (isprint (c) || isspace (c)) {
 		_trace_printf ("%c", c);
 	    } else {
-		int octal = 0;
-		while (c) {
-		    octal *= 10;
-		    octal += c&7;
-		    c /= 8;
-		}
-		_trace_printf ("\\%03d", octal);
+		char buf[4] = { '\\' };
+		int ret_ignored;
+
+		to_octal (c, buf+1, 3);
+		ret_ignored = fwrite (buf, 4, 1, logfile);
 	    }
 	    break;
 	}


More information about the cairo-commit mailing list