chiark / gitweb /
Stop using a zero precision specifier with sprintf ("%.0d") to cause
authorSimon Tatham <anakin@pobox.com>
Fri, 5 Jul 2013 21:54:45 +0000 (21:54 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 5 Jul 2013 21:54:45 +0000 (21:54 +0000)
zero to be generated as the empty string rather than "0". Instead, do
the job by the obvious approach of not calling sprintf at all if the
number is zero. Works around a bug in Emscripten's C library, whose
sprintf doesn't correctly handle that corner case.

[originally from svn r9893]

towers.c

index 35ad8e13848ec0daa18194b9f9affd5ce9e38096..011a4068bf63ba001f046f6619a95bb64a10f267 100644 (file)
--- a/towers.c
+++ b/towers.c
@@ -741,7 +741,10 @@ done
     desc = snewn(40*a, char);
     p = desc;
     for (i = 0; i < 4*w; i++) {
-       p += sprintf(p, "%s%.0d", i?"/":"", clues[i]);
+        if (i)
+            *p++ = '/';
+        if (clues[i])
+            p += sprintf(p, "%d", clues[i]);
     }
     for (i = 0; i < a; i++)
        if (grid[i])