Skip to content

use const-correct types with strchr, strstr, etc.#8932

Open
whitslack wants to merge 1 commit intoElementsProject:masterfrom
whitslack:const-correct
Open

use const-correct types with strchr, strstr, etc.#8932
whitslack wants to merge 1 commit intoElementsProject:masterfrom
whitslack:const-correct

Conversation

@whitslack
Copy link
Collaborator

Because ccan/config.h #defines _GNU_SOURCE, glibc declares qualifier-preserving generic prototypes for the twelve “qualifier-losing search functions” (bsearch, bsearch_s, memchr, strchr, strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr, wcsstr, wmemchr), even in -std=gnu11 mode.

Several places throughout the code base were calling these search functions and inadvertently stripping away the constness of their return values, triggering compilation errors due to -Werror. Fix up these call sites so that the assignments of their return values do not implicitly discard the const qualifier.

Changelog-None

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes. (N/A)
  • Documentation has been reviewed and updated as needed. (N/A)
  • Related issues have been listed and linked, including any that this PR closes. (None found.)
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade (N/A)

Because ccan/config.h #defines _GNU_SOURCE, glibc declares qualifier-
preserving generic prototypes for the twelve "qualifier-losing search
functions" (bsearch, bsearch_s, memchr, strchr, strpbrk, strrchr, strstr,
wcschr, wcspbrk, wcsrchr, wcsstr, wmemchr), even in -std=gnu11 mode.

Several places throughout the code base were calling these search functions
and inadvertently stripping away the constness of their return values,
triggering compilation errors due to -Werror. Fix up these call sites so
that the assignments of their return values do not implicitly discard the
const qualifier.

Changelog-None
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.

1 participant