Small bugfixes for bh_printf family
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 21 May 2020 03:45:13 +0000 (22:45 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 21 May 2020 03:45:13 +0000 (22:45 -0500)
bh.h
onyx

diff --git a/bh.h b/bh.h
index 095abcd600e18fc872b69f911cd9a1f0cdf75845..26ff3bc0f9580e29dbce1a8cc61bfead7d8fb3e4 100644 (file)
--- a/bh.h
+++ b/bh.h
@@ -1340,23 +1340,27 @@ isize bh__printi64(char* str, isize n, bh__print_format format, i64 value) {
        b32 negative = value < 0;
        u32 base = format.base ? format.base : 10, tmp;
 
-       while (value > 0) {
-               tmp = value % base;
-               if (tmp > 9) {
-                       switch (tmp) {
-                       case 10: tmp = 'a'; break;
-                       case 11: tmp = 'b'; break;
-                       case 12: tmp = 'c'; break;
-                       case 13: tmp = 'd'; break;
-                       case 14: tmp = 'e'; break;
-                       case 15: tmp = 'f'; break;
+       if (value == 0) {
+               *--walker = '0';
+       } else {
+               while (value > 0) {
+                       tmp = value % base;
+                       if (tmp > 9) {
+                               switch (tmp) {
+                               case 10: tmp = 'a'; break;
+                               case 11: tmp = 'b'; break;
+                               case 12: tmp = 'c'; break;
+                               case 13: tmp = 'd'; break;
+                               case 14: tmp = 'e'; break;
+                               case 15: tmp = 'f'; break;
+                               }
+                       } else {
+                               tmp += '0';
                        }
-               } else {
-                       tmp += '0';
-               }
 
-               *--walker = tmp;
-               value /= base;
+                       *--walker = tmp;
+                       value /= base;
+               }
        }
 
        if (negative) {
@@ -1382,7 +1386,6 @@ isize bh_snprintf_va(char *str, isize n, char const *fmt, va_list va) {
 
                while (*fmt && *fmt != '%') {
                        *(str++) = *(fmt++);
-                       len++;
                }
 
                if (!*fmt) goto end_of_format;
diff --git a/onyx b/onyx
index 3c7d2ad1c1eeeda64c6002ffb5d4eaf25448da33..53dfc750a1dc8812c5d94fbc5b338c236053f2a9 100755 (executable)
Binary files a/onyx and b/onyx differ