-
Notifications
You must be signed in to change notification settings - Fork 337
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
Fix GCC 15 Wunterminated-string-initialization issues #1543
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,8 +164,10 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, | |
nxt_http_ver_t ver; | ||
nxt_http_target_traps_e trap; | ||
|
||
static const nxt_http_ver_t http11 = { "HTTP/1.1" }; | ||
static const nxt_http_ver_t http10 = { "HTTP/1.0" }; | ||
static const nxt_http_ver_t http11 = | ||
{{ 'H', 'T', 'T', 'P', '/', '1', '.', '1' }}; | ||
static const nxt_http_ver_t http10 = | ||
{{ 'H', 'T', 'T', 'P', '/', '1', '.', '0' }}; | ||
|
||
p = *pos; | ||
|
||
|
@@ -516,7 +518,8 @@ nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos, | |
size_t len; | ||
uint32_t hash; | ||
|
||
static const u_char normal[256] nxt_aligned(64) = | ||
/* The last '\0' is not needed because the string is NUL terminated */ | ||
static const u_char normal[] nxt_aligned(64) = | ||
Comment on lines
-519
to
+522
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @ac000 , That comment is incorrect:
Even though this is a "string literal", it is not a string. The standard prohibits having NUL bytes in the middle of a string, and this is thus not a string. See footnote 75 in C23 (n3220): https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#subsection.6.4.5.
So I would disable the diagnostic. This change (I'm referring specifically to this hunk, and not the entire patch; most of the patch, I like it) is bad for readability, IMO. Instead, I'd take the opportunity to fix the few places where it wouldn't hurt to adapt to the warning, but then disable it until Cheers, Cc: @thesamesam There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Admittedly I just yanked that comment out of nginx, but In this case I would take string to just mean "array of characters". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ughhh. Maybe tell them that their comment is actively harmful?
Yeah, but I this one is really too obscure. The new code feels like a hybrid between a string and a nonstring. And I'd say the "the string is NUL terminated" reminds just so much to a proper string, that it will most likely confuse someone at some point. I'd keep the old version here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, can you point to the comment in nginx? I can't find it with grep. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prior related commits: (sounds like this confused Igor himself.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this context, I would assume "string" just means "string of characters" where string is synonymous with 'series', like you might say "string of robberies". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd use "array" instead of string. Or "string literal", if you want. But using string seems inducing confusion. Maybe I'm too much of a pedantic regarding wording issues; that's my job. :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, if we're being pedantic then I think the word would be pedant. Anyway, I'm probably just going to close this PR and simply disable the warning for now, and then look at sprinkling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lol. True.
I do like that one, however: #1543 (comment) I'd do that change, and then turn the diagnostic off.
:-) |
||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
/* \s ! " # $ % & ' ( ) * + , . / : ; < = > ? */ | ||
"\0\1\0\1\1\1\1\1\0\0\1\1\0" "-" "\1\0" "0123456789" "\0\0\0\0\0\0" | ||
|
@@ -529,7 +532,7 @@ nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos, | |
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; | ||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; | ||
|
||
p = *pos + rp->field_name.length; | ||
hash = rp->field_hash; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,8 +112,8 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args) | |
nxt_sprintf_t spf; | ||
nxt_file_name_t *fn; | ||
|
||
static const u_char hexadecimal[16] = "0123456789abcdef"; | ||
static const u_char HEXADECIMAL[16] = "0123456789ABCDEF"; | ||
static const u_char hexadecimal[] = "0123456789abcdef"; | ||
static const u_char HEXADECIMAL[] = "0123456789ABCDEF"; | ||
Comment on lines
-115
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one I like it. Everything that need not be a nonstring, should be a string. Everybody knows hexadecimal enough that the lost information is negligible. |
||
static const u_char nan[] = "[nan]"; | ||
static const u_char null[] = "[null]"; | ||
static const u_char infinity[] = "[infinity]"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep this as it was. It was much more readable. I'd make it a [[gnu::nonstring]], and wait for a future compiler to re-enable the diagnostic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it looks hideous, but it meant we could keep the warning enabled... but then that whole nxt_http_ver_t thing is only used in that function and it seems to be purely to allow for doing a string comparison using unit64_t's...