Repository navigation
crypto: fix chacha constants under GCC 15 - #20199
Merged
Merged
Conversation
GCC 15 added -Wunterminated-string-initialization, and both constants fill their array exactly, leaving no room for the terminator. Every build with that compiler fails, since crypto/Makefile treats warnings as errors. Neither is used as a string: they are read as sixteen bytes through U8TO32_LITTLE(). Letting the array size follow the literal keeps them readable, costs one byte each, and needs no attribute that only some compilers have. The cipher state is unchanged for both key sizes. Signed-off-by: Royyan Zahir <royzah@gmail.com>
xiaoxiang781216
approved these changes
Sep 20, 2026
acassis
approved these changes
Sep 20, 2026
royzah
added a commit
to tiiuae/nuttx
that referenced
this pull request
Sep 21, 2026
Both strings fill their array exactly, leaving no room for the terminator, so GCC 15 rejects the initialiser and crypto/ will not build. Dropping the explicit bound lets the compiler size them. Merged upstream as apache#20199; carried here until the submodule pin catches up. Signed-off-by: Royyan Zahir <royzah@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
GCC 15 added
-Wunterminated-string-initialization. Both ChaCha constants fill their array exactly, leaving no room for the terminator, andcrypto/Makefileturns warnings into errors:Any build of https://github.com/apache/nuttx/blob/master/crypto/chachapoly.c with that compiler stops there.
How
Neither constant is a string. Both are read as sixteen bytes through
U8TO32_LITTLE(), and nothing looks past index 15. Letting the size follow the literal costs one byte each and needs no attribute that only some compilers have.__attribute__((nonstring))is narrower, but https://github.com/apache/nuttx/blob/master/include/nuttx/compiler.h has no macro for it and adding one across every compiler block is more than this warrants. Happy to go that way instead.Tested
GCC 15.3.0,
aarch64-none-elf, same file:chacha_keysetup()thenchacha_ivsetup()give a byte-identicalinput[16]at 256 and 128 bits.tools/nxstyleclean.