[libav-devel] [PATCH 3/5] samplefmt: Drop a spurious const from av_samples_fill_arrays

Martin Storsjö martin at martin.st
Tue Aug 11 10:51:17 CEST 2015


On Tue, 11 Aug 2015, Anton Khirnov wrote:

> Quoting Luca Barbato (2015-08-03 22:51:50)
>> The resulting mapped array is used as non-const.
>> ---
>>  libavutil/samplefmt.c | 2 +-
>>  libavutil/samplefmt.h | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
>> index bff6004..453ba4c 100644
>> --- a/libavutil/samplefmt.c
>> +++ b/libavutil/samplefmt.c
>> @@ -138,7 +138,7 @@ int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
>>  }
>>
>>  int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
>> -                           const uint8_t *buf, int nb_channels, int nb_samples,
>> +                           uint8_t *buf, int nb_channels, int nb_samples,
>>                             enum AVSampleFormat sample_fmt, int align)
>>  {
>>      int ch, planar, buf_size, line_size;
>> diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h
>> index 8347fac..766b8e6 100644
>> --- a/libavutil/samplefmt.h
>> +++ b/libavutil/samplefmt.h
>> @@ -187,7 +187,7 @@ int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
>>   * @return                 0 on success or a negative error code on failure
>>   */
>>  int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
>> -                           const uint8_t *buf,
>> +                           uint8_t *buf,
>>                             int nb_channels, int nb_samples,
>>                             enum AVSampleFormat sample_fmt, int align);
>>
>> --
>> 1.9.0
>>
>
> Doesn't look right. buf is not modified in this function.

Not in this function, no, but sets the pointer into a struct, where the 
pointer is non-const. So an unwitting caller could use this to strip 
constness.

But I guess the same argument goes here as for strstr; the output (or 
pointer set in the struct in this case) needs to be non-const to work for 
all cases, and the input should be const, to allow using it in that case 
as well.

So with that reasoning, it should stay as it is right now, otherwise you 
can't easily set up an AVFrame pointing to const audio data (e.g. for 
input to encoders).

// Martin


More information about the libav-devel mailing list