Skip to content

Fix discards const from pointer target#881

Merged
ktmf01 merged 1 commit into
xiph:masterfrom
heitbaum:const
May 8, 2026
Merged

Fix discards const from pointer target#881
ktmf01 merged 1 commit into
xiph:masterfrom
heitbaum:const

Conversation

@heitbaum
Copy link
Copy Markdown
Contributor

@heitbaum heitbaum commented Feb 22, 2026

Since glibc-2.43 and ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return pointers into their input arrays now have definitions as macros that return a pointer to a const-qualified type when the input argument is a pointer to a const-qualified type.

char * pointer returns are only being used for comparisons so declare then as const, which matches the input variables.

Fixes:
    ../../../src/share/getopt/getopt.c: In function 'share___getopt_internal':
    ../../../src/share/getopt/getopt.c:781:18: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      781 |     char *temp = my_index (optstring, c);
          |                  ^~~~~~~~
    ../../../src/flac/utils.c: In function 'flac__utils_get_channel_mask_tag':
    ../../../src/flac/utils.c:485:20: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      485 |         if(0 == (p = strchr((const char *)object->data.vorbis_comment.comments[offset].entry, '='))) /* should never happen, but just in case */
          |                    ^
    ../../../src/flac/main.c: In function 'parse_option':
    ../../../src/flac/main.c:1137:43: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     1137 |                                         p = strchr(option_argument, ',');
          |                                           ^

Since glibc-2.43 and ISO C23, the functions bsearch, memchr, strchr,
strpbrk, strrchr, strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr
that return pointers into their input arrays now have definitions as
macros that return a pointer to a const-qualified type when the input
argument is a pointer to a const-qualified type.

char * pointer returns are only being used for comparisons so declare
then as const, which matches the input variables.

Fixes:
    ../../../src/share/getopt/getopt.c: In function 'share___getopt_internal':
    ../../../src/share/getopt/getopt.c:781:18: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      781 |     char *temp = my_index (optstring, c);
          |                  ^~~~~~~~
    ../../../src/flac/utils.c: In function 'flac__utils_get_channel_mask_tag':
    ../../../src/flac/utils.c:485:20: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      485 |         if(0 == (p = strchr((const char *)object->data.vorbis_comment.comments[offset].entry, '='))) /* should never happen, but just in case */
          |                    ^
    ../../../src/flac/main.c: In function 'parse_option':
    ../../../src/flac/main.c:1137:43: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     1137 |                                         p = strchr(option_argument, ',');
          |                                           ^

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
@ktmf01 ktmf01 merged commit b430c3a into xiph:master May 8, 2026
@heitbaum heitbaum deleted the const branch May 8, 2026 22:46
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.

discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]

2 participants