ami: Fix ami_parse_bdf() discarding const from strchr() result#40
Open
amd-vserbu wants to merge 1 commit into
Open
ami: Fix ami_parse_bdf() discarding const from strchr() result#40amd-vserbu wants to merge 1 commit into
amd-vserbu wants to merge 1 commit into
Conversation
Signed-off-by: Vlad-Gabriel Serbu <Vlad-Gabriel.Serbu@amd.com>
Contributor
Author
|
This addresses issue #39 |
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.
Summary
ami_parse_bdf()stores the result ofstrchr()(called on aconst char *) into a non-constchar *. This discards theconstqualifier. It was silently accepted on older toolchains but is a hard error when building in C23 mode against glibc ≥ 2.41 (e.g. GCC 15 / Ubuntu 26.04), where<string.h>provides the C23 const-correctstrchroverloads. Sincesw/AMI/api/Makefilebuilds with-Wall -Werror, the warning is fatal.Change
in
sw/AMI/api/src/ami.c(ami_parse_bdf()).conly ever holds thestrchrresult and is used for a null check and the pointer subtraction(c - bdf); it is never used to mutate the string, soconst char *is correct in all language modes.Diagnostic (before)
Why now
glibc 2.41 added C23 const-correct overloads for
strchr(returnsconst char *for aconst char *argument). The same GCC 14 passes-std=gnu23against glibc 2.39 but fails against glibc 2.43, so this is a glibc/standard-mode interaction, not a single GCC version.-std=gnu17and earlier are unaffected.Testing
Compiled
sw/AMI/apiwith-Wall -Werroracross GCC 11–15 and glibc 2.39 / 2.43, in default,-std=gnu17, and-std=gnu23modes. The change compiles cleanly in every combination; the original code fails only under C23 + glibc ≥ 2.41.