Commit ccdef60e authored by Timothy B. Terriberry's avatar Timothy B. Terriberry
Browse files

Silence scan-build false positives.

The actual guarantees we are making in op_read_native() are:
- if _pcm == NULL, then _buf_sz <= 0 (requirement on the caller),
- op_get_packet_duration() will succeed and return a positive value
   no larger than 120*48 (guaranteed by op_collect_audio_packets()
   filtering out any packets with invalid TOC sequences), and
- nchannels is a small number greater than 0 (guaranteed by the
   validation in opus_parse_head()).
However, trying to assert these things is not enough to convince
 clang to take the nsamples*nchannels>_buf_sz or
 duration*nchannels>_buf_sz branches when _pcm==NULL, so instead
 we have to be a bit more direct.
parent 77121e1b
......@@ -96,6 +96,9 @@ void opus_tags_clear(OpusTags *_tags){
int ci;
ncomments=_tags->comments;
if(_tags->user_comments!=NULL)ncomments++;
else{
OP_ASSERT(ncomments==0);
}
for(ci=ncomments;ci-->0;)_ogg_free(_tags->user_comments[ci]);
_ogg_free(_tags->user_comments);
_ogg_free(_tags->comment_lengths);
......@@ -590,6 +593,7 @@ static int opus_picture_tag_parse_impl(OpusPictureTag *_pic,const char *_tag,
int colors_set;
size_t i;
/*Decode the BASE64 data.*/
OP_ASSERT(_base64_sz>=11);
for(i=0;i<_base64_sz;i++){
opus_uint32 value;
int j;
......
......@@ -2822,6 +2822,7 @@ static int op_read_native(OggOpusFile *_of,
/*If we have buffered samples, return them.*/
if(nsamples>0){
if(nsamples*nchannels>_buf_size)nsamples=_buf_size/nchannels;
OP_ASSERT(_pcm!=NULL||nsamples<=0);
/*Check nsamples again so we don't pass NULL to memcpy() if _buf_size
is zero.
That would technically be undefined behavior, even if the number of
......@@ -2885,6 +2886,7 @@ static int op_read_native(OggOpusFile *_of,
_of->samples_tracked+=trimmed_duration-od_buffer_pos;
}
else{
OP_ASSERT(_pcm!=NULL);
/*Otherwise decode directly into the user's buffer.*/
ret=op_decode(_of,_pcm,pop,duration,nchannels);
if(OP_UNLIKELY(ret<0))return ret;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment