ref: 737cbf573b16b7f4aa0dc9ab8ff7680139e34af0
parent: 6d091e3dccdc1fbf78034169bb7bd969293d8263
author: Timothy B. Terriberry <tterribe@xiph.org>
date: Mon Oct 1 04:04:40 EDT 2012
Fix scan_build static analysis reports. Most of these were dead code left around from rewriting things and things llvm doesn't have enough global information to prove by itself. The one real error was the missing NULL check in opus_tags_parse_impl().
--- a/src/http.c
+++ b/src/http.c
@@ -142,8 +142,6 @@
if(OP_UNLIKELY(op_validate_url_escapes(scheme_end+1)<0))return NULL;
if(scheme_end[1]=='/'&&scheme_end[2]=='/'){
const char *host;
- const char *host_end;
- char host_buf[28];
/*file: URLs can have a host!
Yeah, I was surprised, too, but that's what RFC 1738 says.
It also says, "The file URL scheme is unusual in that it does not specify
@@ -153,21 +151,25 @@
host=scheme_end+3;
/*The empty host is what we expect.*/
if(OP_LIKELY(*host!='/'))path=host;
- /*RFC 1738 says localhost "is interpreted as `the machine from which the
- URL is being interpreted,'" so let's check for it.*/
- host_end=host+strspn(host,OP_URL_PCHAR_BASE);
- /*No <port> allowed.
- This also rejects IP-Literals.*/
- if(*host_end!='/')return NULL;
- /*An escaped "localhost" can take at most 27 characters.*/
- if(OP_UNLIKELY(host_end-host>27))return NULL;
- memcpy(host_buf,host,sizeof(*host_buf)*(host_end-host));
- host_buf[host_end-host]='\0';
- op_unescape_url_component(host_buf);
- op_string_tolower(host_buf);
- /*Some other host: give up.*/
- if(OP_UNLIKELY(strcmp(host_buf,"localhost")!=0))return NULL;
- path=host_end;
+ else{
+ const char *host_end;
+ char host_buf[28];
+ /*RFC 1738 says localhost "is interpreted as `the machine from which the
+ URL is being interpreted,'" so let's check for it.*/
+ host_end=host+strspn(host,OP_URL_PCHAR_BASE);
+ /*No <port> allowed.
+ This also rejects IP-Literals.*/
+ if(*host_end!='/')return NULL;
+ /*An escaped "localhost" can take at most 27 characters.*/
+ if(OP_UNLIKELY(host_end-host>27))return NULL;
+ memcpy(host_buf,host,sizeof(*host_buf)*(host_end-host));
+ host_buf[host_end-host]='\0';
+ op_unescape_url_component(host_buf);
+ op_string_tolower(host_buf);
+ /*Some other host: give up.*/
+ if(OP_UNLIKELY(strcmp(host_buf,"localhost")!=0))return NULL;
+ path=host_end;
+ }
}
else path=scheme_end+1;
path_end=path+strspn(path,OP_URL_PATH);
--- a/src/info.c
+++ b/src/info.c
@@ -164,8 +164,10 @@
_data+=count;
len-=count;
}
- _tags->user_comments[ncomments]=NULL;
- _tags->comment_lengths[ncomments]=0;
+ if(_tags!=NULL){
+ _tags->user_comments[ncomments]=NULL;
+ _tags->comment_lengths[ncomments]=0;
+ }
return 0;
}
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -311,12 +311,10 @@
while(_of->offset<end){
opus_int64 llret;
ogg_uint32_t serialno;
- int prev_preferred_found;
llret=op_get_next_page(_of,&og,end-_of->offset);
if(OP_UNLIKELY(llret<OP_FALSE))return (int)llret;
else if(llret==OP_FALSE)break;
serialno=ogg_page_serialno(&og);
- prev_preferred_found=preferred_found;
/*Save the information for this page.
We're not interested in the page itself... just the serial number, byte
offset, page size, and granule position.*/
@@ -711,7 +709,6 @@
int pi;
if(_og==NULL)_og=&og;
serialno=_of->os.serialno;
- cur_page_gp=-1;
op_count=0;
/*We shouldn't have to initialize total_duration, but gcc is too dumb to
figure out that op_count>0 implies we've been through the whole loop at
@@ -986,13 +983,11 @@
int clinks;
ogg_uint32_t *serialnos;
int nserialnos;
- opus_int64 begin;
ogg_int64_t total_duration;
int nsr;
int ret;
links=_of->links;
nlinks=clinks=_of->nlinks;
- begin=0;
total_duration=0;
/*We start with one seek record, for the last page in the file.
We build up a list of records for places we seek to during link
@@ -1003,7 +998,6 @@
improve the lower bound on the location where the next link starts.*/
nsr=1;
for(;;){
- opus_int64 data_offset;
opus_int64 end_searched;
opus_int64 bisect;
opus_int64 next;
@@ -1021,7 +1015,6 @@
if(OP_UNLIKELY(links==NULL))return OP_EFAULT;
_of->links=links;
}
- data_offset=_searched;
/*Invariants:
We have the headers and serial numbers for the link beginning at 'begin'.
We have the offset and granule position of the last page in the file
@@ -1144,7 +1137,6 @@
always starts with a seek.*/
ret=op_find_initial_pcm_offset(_of,links+nlinks,NULL);
if(OP_UNLIKELY(ret<0))return ret;
- begin=next;
_searched=_of->offset;
/*Mark the current link count so it can be cleaned up on error.*/
_of->nlinks=++nlinks;
@@ -1942,17 +1934,11 @@
}
int op_raw_seek(OggOpusFile *_of,opus_int64 _pos){
- OggOpusLink *links;
- int nlinks;
- int cur_link;
int ret;
if(OP_UNLIKELY(_of->ready_state<OP_OPENED))return OP_EINVAL;
/*Don't dump the decoder state if we can't seek.*/
if(OP_UNLIKELY(!_of->seekable))return OP_ENOSEEK;
if(OP_UNLIKELY(_pos<0)||OP_UNLIKELY(_pos>_of->end))return OP_EINVAL;
- links=_of->links;
- nlinks=_of->nlinks;
- cur_link=_of->cur_link;
/*Clear out any buffered, decoded data.*/
op_decode_clear(_of);
_of->bytes_tracked=0;
@@ -1963,10 +1949,11 @@
/*If we hit EOF, op_fetch_and_process_page() leaves us uninitialized.
Instead, jump to the end.*/
if(ret==OP_EOF){
- cur_link=nlinks-1;
+ int cur_link;
op_decode_clear(_of);
+ cur_link=_of->nlinks-1;
_of->cur_link=cur_link;
- _of->prev_packet_gp=links[cur_link].pcm_end;
+ _of->prev_packet_gp=_of->links[cur_link].pcm_end;
_of->cur_discard_count=0;
ret=0;
}
@@ -2276,12 +2263,14 @@
OggOpusLink *links;
ogg_int64_t pcm_offset;
ogg_int64_t delta;
+ int ret;
int li;
links=_of->links;
pcm_offset=0;
OP_ASSERT(_li<_of->nlinks);
for(li=0;li<_li;li++){
- op_granpos_diff(&delta,links[li].pcm_end,links[li].pcm_start);
+ ret=op_granpos_diff(&delta,links[li].pcm_end,links[li].pcm_start);
+ OP_ASSERT(!ret);
delta-=links[li].head.pre_skip;
pcm_offset+=delta;
}
@@ -2290,7 +2279,8 @@
_gp=links[_li].pcm_end;
}
if(OP_LIKELY(op_granpos_cmp(_gp,links[_li].pcm_start)>0)){
- op_granpos_diff(&delta,_gp,links[_li].pcm_start);
+ ret=op_granpos_diff(&delta,_gp,links[_li].pcm_start);
+ OP_ASSERT(!ret);
if(delta<links[_li].head.pre_skip)delta=0;
else delta-=links[_li].head.pre_skip;
pcm_offset+=delta;
@@ -2327,7 +2317,7 @@
int li;
links=_of->links;
nlinks=_of->nlinks;
- nchannels_max=0;
+ nchannels_max=1;
for(li=0;li<nlinks;li++){
nchannels_max=OP_MAX(nchannels_max,links[li].head.channel_count);
}