Fix -Wdiscarded-qualifiers warning in kms_request.c#2354
Closed
jeroen wants to merge 1 commit into
Closed
Conversation
Remove unnecessary (const char *) casts on the strchr arguments in
parse_query_params. In C23 (the default for GCC 15) strchr is
const-generic: passing a const char * makes it return const char *,
which cannot be assigned to the non-const 'equals' and 'amp' pointers:
kms/kms_request.c: In function 'parse_query_params':
kms/kms_request.c:35:14: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
35 | equals = strchr ((const char *) p, '=');
| ^
kms/kms_request.c:40:11: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
40 | amp = strchr ((const char *) equals, '&');
| ^
Since p and equals are already plain char *, the casts serve no
purpose and dropping them is warning-free on both old and new
compilers.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jeroen
added a commit
to jeroen/mongolite
that referenced
this pull request
Jul 20, 2026
In C23 (default for GCC 15) strchr is const-generic, so the explicit (const char *) casts made it return const char *, which cannot be assigned to the non-const 'equals' and 'amp' pointers. Upstreamed as mongodb/mongo-c-driver#2354 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
kevinAlbs
self-requested a review
July 20, 2026 16:39
Collaborator
|
Thanks for the PR @jeroen. This file is copied from libmongocrypt. Applied this fix in mongodb/libmongocrypt#1206 and can update the copy to the latest libmongocrypt sources after merging. |
Collaborator
|
Closing in favor of #2355 which updates the kms-message sources to include mongodb/libmongocrypt#1206. Thanks again @jeroen for bringing this to our attention. |
Contributor
Author
|
Thank you! |
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.
This fixes a (problematic)
-Wdiscarded-qualifierswarning that we get in the R bindings ongcc-16:AI summary: In C23 (the default language standard for GCC 15),
strchris const-generic: when passed aconst char *it returns aconst char *. The explicit(const char *)casts inparse_query_paramstherefore make the result unassignable to the non-constequalsandamppointers.Since
pandequalsare already plainchar *, the casts serve no purpose; removing them is warning-free on both old and new compilers.