Skip to content

Fix -Wunterminated-string-initialization warning #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,13 @@ size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_
*/

/* 2 <= base <= 36 */
char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler is right to complain because sizeof("0123456789abcdefghijklmnopqrstuvwxyz") is 37, not 36.

char const digits36[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'
};


#define USE_SPECIAL_RADIX_10 1 // special case base 10 radix conversions
#define USE_SINGLE_CASE_FAST 1 // special case single digit numbers
Expand Down
9 changes: 7 additions & 2 deletions tests/test_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ size_t i64toa_radix(char buf[minimum_length(66)], int64_t n, unsigned base);
*/

/* 2 <= base <= 36 */
char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
char const digits36[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'
};

/*---- variants ----*/

Expand Down Expand Up @@ -238,7 +243,7 @@ define_i64toa(shift)
#endif /* TEST_SHIFTBUF */

#if defined(TEST_DIGIT_PAIRS) || defined(TEST_DIGIT_1PASS)
static char const digits100[200] =
static char const digits100[] =
"00010203040506070809"
"10111213141516171819"
"20212223242526272829"
Expand Down
Loading