This repository was archived by the owner on Oct 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 362
Tag some char arrays with __attribute__ ((__nonstring__)) #1575
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8dca58f
to
6a27240
Compare
hongzhidao
reviewed
Mar 19, 2025
This is a wrapper around __attribute__ ((__nonstring__)). Traditionally this was used to mark char array variables that intentionally lacked a terminating NUL byte, this would then cause warning to either be quelled or emitted for various memory/string functions. GCC 15 introduced a new warning, Wunterminated-string-initialization, which will always warn on things like static const char hex[16] = "0123456789ABCDEF"; However this is very much intentionally not NUL terminated. When the Wunterminated-string-initialization patch went in, the "nonstriong" attribute didn't quell this warning, however a patch has since gone in (prior to the GCC 15 release) to enable this attribute to quell this warning. In Unit we disabled this new warning with an eye to being able to re-enable it again, this patch is the first in a series to do just that. So the above example would become static const char hex[16] NXT_NONSTRING = "0123456789ABCDEF"; Link: <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=44c9403ed1833ae71a59e84f9e37af3182be0df5> Link: <https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=622968990beee7499e951590258363545b4a3b57> Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178#c21> Cc: Alejandro Colomar <alx@kernel.org> Reviewed-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Thanks to @alejandro-colomar pointing out my idiocy, your qualms about the
|
alejandro-colomar
approved these changes
Mar 19, 2025
hongzhidao
approved these changes
Mar 20, 2025
In Unit we have a number of character arrays which are intentionally not NUL terminated. With GCC 15 this static const char hex[16] = "0123456789ABCDEF"; will trigger a warning like $ gcc -Wextra -c nonstring.c nonstring.c: In function ‘hexit’: nonstring.c:9:37: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (17 chars into 16 available) [-Wunterminated-string-initialization] 9 | static const char hex[16] = "0123456789ABCDEF"; | ^~~~~~~~~~~~~~~~~~ By adding NXT_NONSTRING like static const char hex[16] NXT_NONSTRING = "0123456789ABCDEF"; we no longer get the warning. Cc: Alejandro Colomar <alx@kernel.org> Co-authored-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Now that we are able to use the "nonstring" variable attribute to quell this warning, we no longer need to disable it. The good thing is there was never a released version of GCC where the warning couldn't be quelled by the attribute. Fixes: 1503782 ("Fix build with GCC 15") Cc: Alejandro Colomar <alx@kernel.org> Reviewed-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Fix a commit message.
|
Thanks guys! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As previously promised, this PR comprises three commits that allow us to re-enable the new GCC 15 warning
Wunterminated-string-initialization
.__attribute__ ((__nonstring__))
As a reminder, this attribute is used to mark character arrays that are intentionally not NUL terminated.
The second commit tags various character arrays with this attribute.
The third commit removes the disabling of this new warning.