Skip to content

Suppress new gcc-15 -Wunterminated-string-initialization#796

Merged
jforissier merged 1 commit into
OP-TEE:masterfrom
denix0:master
May 9, 2025
Merged

Suppress new gcc-15 -Wunterminated-string-initialization#796
jforissier merged 1 commit into
OP-TEE:masterfrom
denix0:master

Conversation

@denix0
Copy link
Copy Markdown
Contributor

@denix0 denix0 commented May 7, 2025

GCC 15 now warns when character arrays are being initialized by strings
and terminating NUL character doesn't fit. GCC 15.1 also allows marking
such arrays with nonstring attribute to suppress the warning. W/o such
attribute, the warning becomes error due to the global -Werror. Add the
attribute accordingly.

@mikkorapeli-linaro
Copy link
Copy Markdown

Fixes optee-test yocto builds from meta-arm.

@jforissier
Copy link
Copy Markdown
Contributor

Thanks @denix0

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

@jenswikl
Copy link
Copy Markdown
Contributor

jenswikl commented May 7, 2025

Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

@etienne-lms
Copy link
Copy Markdown
Contributor

Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>

@rossburton
Copy link
Copy Markdown
Contributor

FWIW, our clang builds fail with this patch:

./regression_4000_data.h:7917:78: error: unknown attribute 'nonstring' ignored [-Werror,-Wunknown-attributes]

@mikkorapeli-linaro
Copy link
Copy Markdown

FWIW, our clang builds fail with this patch:

./regression_4000_data.h:7917:78: error: unknown attribute 'nonstring' ignored [-Werror,-Wunknown-attributes]

#797 should help by disabling Werror. Maybe we can backport this to meta-arm...

@rossburton
Copy link
Copy Markdown
Contributor

#797 should help by disabling Werror. Maybe we can backport this to meta-arm...

Yes, I'd approve that.

@denix0
Copy link
Copy Markdown
Contributor Author

denix0 commented May 7, 2025

Is clang behind gcc for once? :)

Anyway, according to the manual clang 21 does have support for this attribute, but in Yocto we have 20.1 for now:
https://clang.llvm.org/docs/AttributeReference.html#nonstring

@mikkorapeli-linaro
Copy link
Copy Markdown

I hope #ifdef's for gcc/clang and/or versions are not needed... or feature checks?

@jforissier
Copy link
Copy Markdown
Contributor

I hope #ifdef's for gcc/clang and/or versions are not needed... or feature checks?

#if __has_attribute(nonstring) should work

@denix0
Copy link
Copy Markdown
Contributor Author

denix0 commented May 7, 2025

This nonstring attribute has been added to clang only last week:
llvm/llvm-project#137705

@denix0
Copy link
Copy Markdown
Contributor Author

denix0 commented May 7, 2025

I hope #ifdef's for gcc/clang and/or versions are not needed... or feature checks?

#if __has_attribute(nonstring) should work

I've just updated the commit with this check.

Should I collect all the early reviews in the commit message, or wait for the new ones?

@jforissier
Copy link
Copy Markdown
Contributor

I hope #ifdef's for gcc/clang and/or versions are not needed... or feature checks?

#if __has_attribute(nonstring) should work

I've just updated the commit with this check.

Should I collect all the early reviews in the commit message, or wait for the new ones?

Acked-by's can usually be kept when changes are minor. Reviewed-by's are a different story, but you have mine anyways:

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

Thanks!

GCC 15 now warns when character arrays are being initialized by strings
and terminating NUL character doesn't fit. GCC 15.1 also allows marking
such arrays with nonstring attribute to suppress the warning. W/o such
attribute, the warning becomes error due to the global -Werror. Add the
attribute accordingly.

Fixes these errors:

| ./regression_4000_data.h:7919:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (20 chars into 19 available) [-Werror=unterminated-string-initialization]
|  7919 |         "encryption standard";
|       |         ^~~~~~~~~~~~~~~~~~~~~
| ./regression_4000_data.h:8387:9: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (113 chars into 112 available) [-Werror=unterminated-string-initialization]
|  8387 |         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomn"
|       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ./regression_4000.c:1295:47: error: initializer-string for array of 'unsigned char' truncates NUL terminator but destination lacks 'nonstring' attribute (4 chars into 3 available) [-Werror=unterminated-string-initialization]
|  1295 | static const uint8_t hash_data_sm3_a1_in[3] = "abc";
|       |                                               ^~~~~

Signed-off-by: Denys Dmytriyenko <denys@konsulko.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
@denix0
Copy link
Copy Markdown
Contributor Author

denix0 commented May 7, 2025

I've just updated the commit with this check.
Should I collect all the early reviews in the commit message, or wait for the new ones?

Acked-by's can usually be kept when changes are minor. Reviewed-by's are a different story, but you have mine anyways:

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

Thanks!

Ok, updated the commit one more time with reviews and acks. Thanks for all the feedback.

@jforissier jforissier merged commit 758da3d into OP-TEE:master May 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants