Skip to content

Fix discards const from pointer target#881

Open
heitbaum wants to merge 1 commit intoxiph:masterfrom
heitbaum:const
Open

Fix discards const from pointer target#881
heitbaum wants to merge 1 commit intoxiph:masterfrom
heitbaum:const

Conversation

@heitbaum
Copy link

@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>
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]

1 participant