]> git.kaiwu.me - quickjs.git/commitdiff
Avoid initializer-string warning for the digits array
authorNick Vatamaniuc <vatamane@gmail.com>
Tue, 24 Mar 2026 04:46:16 +0000 (00:46 -0400)
committerNick Vatamaniuc <vatamane@gmail.com>
Tue, 24 Mar 2026 04:53:29 +0000 (00:53 -0400)
Some newer compilers emit this warning:

```
warning: initializer-string for character array is too long, array size is 36
     but initializer has size 37 (including the null terminating character);
     did you mean to use the 'nonstring' attribute? [-Wunterminated-string-initialization]
 12146 | static char const digits[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
       |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

To avoid the warning initialize the array as individual characters

quickjs.c

index 2b33bfa5f5e34794b4f819ad758d04485017312f..7b5d654287e52f5b7408980e1f652e3da2573407 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -12143,7 +12143,11 @@ static JSBigInt *js_bigint_from_string(JSContext *ctx,
 }
 
 /* 2 <= base <= 36 */
-static char const digits[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
+static char const digits[36] = {
+  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
+  'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+  'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
+};
 
 /* special version going backwards */
 /* XXX: use dtoa.c */