Skip to content

fix discards 'const' qualifier from pointer#262

Open
heitbaum wants to merge 1 commit intoralph-irving:masterfrom
heitbaum:const
Open

fix discards 'const' qualifier from pointer#262
heitbaum wants to merge 1 commit intoralph-irving:masterfrom
heitbaum:const

Conversation

@heitbaum
Copy link

@heitbaum heitbaum commented Mar 4, 2026

For 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.

https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html

Fixes:

decode.c: In function 'decode_init':
decode.c:159:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  159 |         if (!strstr(exclude_codecs, "dsd")      && (!include_codecs || (order_codecs = strstr(include_codecs, "dsd"))))
      |                                                                                      ^
decode.c:166:82: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  166 |         if (!strstr(exclude_codecs, "alac") && (!include_codecs || (order_codecs = strstr(include_codecs, "alac"))))
      |                                                                                  ^
decode.c:168:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  168 |         if (!strstr(exclude_codecs, "wma")      && (!include_codecs || (order_codecs = strstr(include_codecs, "wma"))))
      |                                                                                      ^
decode.c:172:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  172 |         if (!strstr(exclude_codecs, "aac")      && (!include_codecs || (order_codecs = strstr(include_codecs, "aac"))))
      |                                                                                      ^
decode.c:175:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  175 |         if (!strstr(exclude_codecs, "ogg")      && (!include_codecs || (order_codecs = strstr(include_codecs, "ogg"))))
      |                                                                                      ^
decode.c:181:82: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  181 |         if (!strstr(exclude_codecs, "flac") && (!include_codecs || (order_codecs = strstr(include_codecs, "flac"))))
      |                                                                                  ^
decode.c:183:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  183 |         if (!strstr(exclude_codecs, "pcm")      && (!include_codecs || (order_codecs = strstr(include_codecs, "pcm"))))
      |                                                                                      ^
decode.c:189:51: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  189 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mad"))))
      |                                                   ^
decode.c:189:101: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  189 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mad"))))
      |                                                                                                     ^
decode.c:192:51: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  192 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mpg"))))
      |                                                   ^
decode.c:192:101: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  192 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mpg"))))
      |                                                                                                     ^
ffmpeg.c: In function 'ff_decode':
ffmpeg.c:348:23: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  348 |                 codec = AVCODEC(ff, find_decoder, ff->codecP->codec_id);
      |                       ^
ffmpeg.c: In function 'ff_open_wma':
ffmpeg.c:598:26: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  598 |         ff->input_format = AV(ff, find_input_format, "asf");
      |                          ^
ffmpeg.c: In function 'ff_open_alac':
ffmpeg.c:614:26: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  614 |         ff->input_format = AV(ff, find_input_format, "mp4");
      |                          ^

For 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.

https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html

Fixes:
decode.c: In function 'decode_init':
decode.c:159:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  159 |         if (!strstr(exclude_codecs, "dsd")      && (!include_codecs || (order_codecs = strstr(include_codecs, "dsd"))))
      |                                                                                      ^
decode.c:166:82: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  166 |         if (!strstr(exclude_codecs, "alac") && (!include_codecs || (order_codecs = strstr(include_codecs, "alac"))))
      |                                                                                  ^
decode.c:168:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  168 |         if (!strstr(exclude_codecs, "wma")      && (!include_codecs || (order_codecs = strstr(include_codecs, "wma"))))
      |                                                                                      ^
decode.c:172:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  172 |         if (!strstr(exclude_codecs, "aac")      && (!include_codecs || (order_codecs = strstr(include_codecs, "aac"))))
      |                                                                                      ^
decode.c:175:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  175 |         if (!strstr(exclude_codecs, "ogg")      && (!include_codecs || (order_codecs = strstr(include_codecs, "ogg"))))
      |                                                                                      ^
decode.c:181:82: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  181 |         if (!strstr(exclude_codecs, "flac") && (!include_codecs || (order_codecs = strstr(include_codecs, "flac"))))
      |                                                                                  ^
decode.c:183:86: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  183 |         if (!strstr(exclude_codecs, "pcm")      && (!include_codecs || (order_codecs = strstr(include_codecs, "pcm"))))
      |                                                                                      ^
decode.c:189:51: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  189 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mad"))))
      |                                                   ^
decode.c:189:101: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  189 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mad"))))
      |                                                                                                     ^
decode.c:192:51: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  192 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mpg"))))
      |                                                   ^
decode.c:192:101: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  192 |                 (!include_codecs || (order_codecs = strstr(include_codecs, "mp3")) || (order_codecs = strstr(include_codecs, "mpg"))))
      |                                                                                                     ^
ffmpeg.c: In function 'ff_decode':
ffmpeg.c:348:23: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  348 |                 codec = AVCODEC(ff, find_decoder, ff->codecP->codec_id);
      |                       ^
ffmpeg.c: In function 'ff_open_wma':
ffmpeg.c:598:26: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  598 |         ff->input_format = AV(ff, find_input_format, "asf");
      |                          ^
ffmpeg.c: In function 'ff_open_alac':
ffmpeg.c:614:26: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  614 |         ff->input_format = AV(ff, find_input_format, "mp4");
      |                          ^

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
u8_t *readbuf;
bool end_of_stream;
AVInputFormat *input_format;
const AVInputFormat *input_format;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change produces compiler warnings for older glibc and ffmpeg versions.

ffmpeg.c:294:3: warning: passing argument 3 of 'avformat_open_input' discards 'const' qualifier from pointer target type [enabled by default]
In file included from ffmpeg.c:26:0:
./include/libavformat/avformat.h:2312:5: note: expected 'struct AVInputFormat *' but argument is of type 'const struct AVInputFormat *'```

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.

2 participants