ref: 4b70af03f9038b74b51471e489c2b9cf0a0f1d0b
parent: f75d06a955bd0a32f8abec56596e392e4d0ab535
author: Timothy B. Terriberry <tterribe@xiph.org>
date: Wed Oct 24 05:57:25 EDT 2012
Replace return code checks with OP_ALWAYS_TRUE(). Instead of assigning the return code to a local variable and then using OP_ASSERT(), define a new OP_ALWAYS_TRUE() macro that still evaluates its argument when assertions are disabled. This avoids -Wunused-but-set-variable warnings from clang and useless scan-build reports (if scan-build is run without assertions enabled).
--- a/src/http.c
+++ b/src/http.c
@@ -597,11 +597,10 @@
# else
# define OP_SO_LEVEL SOL_TCP
# endif
- int ret;
- ret=setsockopt(_fd,OP_SO_LEVEL,TCP_NODELAY,&_nodelay,sizeof(_nodelay));
/*It doesn't really matter if this call fails, but it would be interesting
to hit a case where it does.*/
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!setsockopt(_fd,OP_SO_LEVEL,TCP_NODELAY,
+ &_nodelay,sizeof(_nodelay)));
# endif
}
@@ -841,11 +840,9 @@
opus_int32 read_delta_ms;
opus_int64 read_delta_bytes;
opus_int64 read_rate;
- int ret;
read_delta_bytes=_conn->read_bytes;
if(read_delta_bytes<=0)return;
- ret=ftime(&read_time);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!ftime(&read_time));
read_delta_ms=op_time_diff_ms(&read_time,&_conn->read_time);
read_rate=_conn->read_rate;
read_delta_ms=OP_MAX(read_delta_ms,1);
@@ -1395,9 +1392,8 @@
if(OP_UNLIKELY(retry_bio==NULL))return OP_EFAULT;
SSL_set_bio(_ssl_conn,retry_bio,_ssl_bio);
SSL_set_connect_state(_ssl_conn);
- ret=SSL_connect(_ssl_conn);
/*This shouldn't succeed, since we can't read yet.*/
- OP_ASSERT(ret<0);
+ OP_ALWAYS_TRUE(SSL_connect(_ssl_conn)<0);
SSL_set_bio(_ssl_conn,_ssl_bio,_ssl_bio);
/*Only now do we disable write coalescing, to allow the CONNECT
request and the start of the TLS handshake to be combined.*/
@@ -1521,8 +1517,7 @@
_stream->free_head=_conn->next;
_conn->next=_stream->lru_head;
_stream->lru_head=_conn;
- ret=ftime(_start_time);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!ftime(_start_time));
*&_conn->read_time=*_start_time;
_conn->read_bytes=0;
_conn->read_rate=0;
@@ -1691,12 +1686,9 @@
ret|=op_sb_ensure_capacity(_sb,nbuf_total);
if(OP_UNLIKELY(ret<0))return ret;
_sb->nbuf=nbuf_total-user_pass_len;
- ret=op_sb_append(_sb,_user,user_len);
- OP_ASSERT(!ret);
- ret=op_sb_append(_sb,":",1);
- OP_ASSERT(!ret);
- ret=op_sb_append(_sb,_pass,pass_len);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_sb_append(_sb,_user,user_len));
+ OP_ALWAYS_TRUE(!op_sb_append(_sb,":",1));
+ OP_ALWAYS_TRUE(!op_sb_append(_sb,_pass,pass_len));
op_base64_encode(_sb->buf+nbuf_total-base64_len,
_sb->buf+nbuf_total-user_pass_len,user_pass_len);
return op_sb_append(_sb,"\r\n",2);
@@ -1901,8 +1893,7 @@
if(OP_UNLIKELY(ret<0))return ret;
ret=op_http_conn_read_response(_stream->conns+0,&_stream->response);
if(OP_UNLIKELY(ret<0))return ret;
- ret=ftime(&end_time);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!ftime(&end_time));
next=op_http_parse_status_line(&v1_1_compat,&status_code,
_stream->response.buf);
if(OP_UNLIKELY(next==NULL))return OP_FALSE;
@@ -2258,8 +2249,7 @@
if(OP_UNLIKELY(ret<0))return ret;
ret=op_http_conn_handle_response(_stream,_conn);
if(OP_UNLIKELY(ret!=0))return OP_FALSE;
- ret=ftime(&end_time);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!ftime(&end_time));
_stream->cur_conni=_conn-_stream->conns;
OP_ASSERT(_stream->cur_conni>=0&&_stream->cur_conni<OP_NCONNS_MAX);
/*The connection has been successfully opened.
@@ -2552,10 +2542,7 @@
op_http_conn_read_rate_update(stream->conns+ci);
*&seek_time=*&stream->conns[ci].read_time;
}
- else{
- ret=ftime(&seek_time);
- OP_ASSERT(!ret);
- }
+ else OP_ALWAYS_TRUE(!ftime(&seek_time));
/*If we seeked past the end of the stream, just disable the active
connection.*/
if(pos>=content_length){
--- a/src/internal.h
+++ b/src/internal.h
@@ -72,10 +72,12 @@
if(OP_UNLIKELY(!(_cond)))OP_FATAL("assertion failed: " #_cond); \
} \
while(0)
+# define OP_ALWAYS_TRUE(_cond) OP_ASSERT(_cond)
# else
# define OP_FATAL(_str) abort()
# define OP_ASSERT(_cond)
+# define OP_ALWAYS_TRUE(_cond) ((void)(_cond))
# endif
# define OP_INT64_MAX ((ogg_int64_t)0x7FFFFFFFFFFFFFFFLL)
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -817,11 +817,9 @@
/*Timestamp the individual packets.*/
prev_packet_gp=pcm_start;
for(pi=0;pi<op_count;pi++){
- int ret;
if(cur_page_eos){
ogg_int64_t diff;
- ret=op_granpos_diff(&diff,cur_page_gp,prev_packet_gp);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,cur_page_gp,prev_packet_gp));
diff=durations[pi]-diff;
/*If we have samples to trim...*/
if(diff>0){
@@ -836,9 +834,8 @@
}
}
/*Update the granule position as normal.*/
- ret=op_granpos_add(&_of->op[pi].granulepos,
- prev_packet_gp,durations[pi]);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_add(&_of->op[pi].granulepos,
+ prev_packet_gp,durations[pi]));
prev_packet_gp=_of->op[pi].granulepos;
}
/*Update the packet count after end-trimming.*/
@@ -1604,7 +1601,6 @@
ogg_int64_t op_pcm_total(OggOpusFile *_of,int _li){
OggOpusLink *links;
ogg_int64_t diff;
- int ret;
int nlinks;
nlinks=_of->nlinks;
if(OP_UNLIKELY(_of->ready_state<OP_OPENED)
@@ -1621,14 +1617,14 @@
int li;
pcm_total=0;
for(li=0;li<nlinks;li++){
- ret=op_granpos_diff(&diff,links[li].pcm_end,links[li].pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,
+ links[li].pcm_end,links[li].pcm_start));
pcm_total+=diff-links[li].head.pre_skip;
}
return pcm_total;
}
- ret=op_granpos_diff(&diff,links[_li].pcm_end,links[_li].pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,
+ links[_li].pcm_end,links[_li].pcm_start));
return diff-links[_li].head.pre_skip;
}
@@ -1921,12 +1917,11 @@
}
else{
/*Update the granule position as normal.*/
- ret=op_granpos_add(&cur_packet_gp,cur_packet_gp,durations[pi]);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_add(&cur_packet_gp,
+ cur_packet_gp,durations[pi]));
}
_of->op[pi].granulepos=cur_packet_gp;
- ret=op_granpos_diff(&diff,cur_page_gp,cur_packet_gp);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,cur_page_gp,cur_packet_gp));
}
}
else{
@@ -1956,8 +1951,8 @@
}
total_duration-=durations[pi];
OP_ASSERT(total_duration>=0);
- ret=op_granpos_add(&cur_packet_gp,cur_packet_gp,durations[pi]);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_add(&cur_packet_gp,
+ cur_packet_gp,durations[pi]));
_of->op[pi].granulepos=cur_packet_gp;
}
OP_ASSERT(total_duration==0);
@@ -2007,7 +2002,6 @@
ogg_int64_t duration;
int nlinks;
int li;
- int ret;
OP_ASSERT(_pcm_offset>=0);
nlinks=_of->nlinks;
links=_of->links;
@@ -2016,8 +2010,7 @@
opus_int32 pre_skip;
pcm_start=links[li].pcm_start;
pre_skip=links[li].head.pre_skip;
- ret=op_granpos_diff(&duration,links[li].pcm_end,pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&duration,links[li].pcm_end,pcm_start));
duration-=pre_skip;
if(_pcm_offset<duration){
_pcm_offset+=pre_skip;
@@ -2085,8 +2078,7 @@
}
/*Special case seeking to the start of the link.*/
pre_skip=link->head.pre_skip;
- ret=op_granpos_add(&pcm_pre_skip,pcm_start,pre_skip);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_add(&pcm_pre_skip,pcm_start,pre_skip));
if(op_granpos_cmp(_target_gp,pcm_pre_skip)<0)end=boundary=begin;
else{
end=boundary=link->end_offset;
@@ -2109,8 +2101,7 @@
page without a granule position after reporting a hole.*/
if(OP_LIKELY(gp!=-1)&&OP_LIKELY(op_granpos_cmp(pcm_start,gp)<0)
&&OP_LIKELY(op_granpos_cmp(pcm_end,gp)>0)){
- ret=op_granpos_diff(&diff,gp,_target_gp);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,gp,_target_gp));
/*We only actually use the current time if either
a) We can cut off more than half the range, or
b) We're seeking sufficiently close to the current position that
@@ -2150,10 +2141,8 @@
if(force_bisect)bisect=begin+(end-begin>>1);
else{
ogg_int64_t diff2;
- ret=op_granpos_diff(&diff,_target_gp,pcm_start);
- OP_ASSERT(!ret);
- ret=op_granpos_diff(&diff2,pcm_end,pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,_target_gp,pcm_start));
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff2,pcm_end,pcm_start));
/*Take a (pretty decent) guess.*/
bisect=begin+op_rescale64(diff,diff2,end-begin)-OP_CHUNK_SIZE;
}
@@ -2209,8 +2198,7 @@
position.*/
best=begin;
best_gp=pcm_start=gp;
- ret=op_granpos_diff(&diff,_target_gp,pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,_target_gp,pcm_start));
/*If we're more than a second away from our target, break out and
do another bisection.*/
if(diff>48000)break;
@@ -2253,8 +2241,7 @@
/*By default, discard 80 ms of data after a seek, unless we seek
into the pre-skip region.*/
cur_discard_count=80*48;
- ret=op_granpos_diff(&diff,best_gp,pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,best_gp,pcm_start));
OP_ASSERT(diff>=0);
/*If we start at the beginning of the pre-skip region, or we're at least
80 ms from the end of the pre-skip region, we discard to the end of the
@@ -2296,8 +2283,7 @@
/*Now skip samples until we actually get to our target.*/
link=_of->links+li;
pcm_start=link->pcm_start;
- ret=op_granpos_diff(&_pcm_offset,target_gp,pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&_pcm_offset,target_gp,pcm_start));
/*Figure out where we should skip to.*/
if(_pcm_offset<=link->head.pre_skip)skip=0;
else skip=OP_MAX(_pcm_offset-80*48,0);
@@ -2324,8 +2310,7 @@
ret=op_fetch_and_process_page(_of,NULL,-1,1,0,1);
if(OP_UNLIKELY(ret<=0))return OP_EBADLINK;
}
- ret=op_granpos_diff(&diff,prev_packet_gp,pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&diff,prev_packet_gp,pcm_start));
/*We skipped too far.
Either the timestamps were illegal or there was a hole in the data.*/
if(diff>skip)return OP_EBADLINK;
@@ -2351,14 +2336,13 @@
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++){
- ret=op_granpos_diff(&delta,links[li].pcm_end,links[li].pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&delta,
+ links[li].pcm_end,links[li].pcm_start));
delta-=links[li].head.pre_skip;
pcm_offset+=delta;
}
@@ -2367,8 +2351,7 @@
_gp=links[_li].pcm_end;
}
if(OP_LIKELY(op_granpos_cmp(_gp,links[_li].pcm_start)>0)){
- ret=op_granpos_diff(&delta,_gp,links[_li].pcm_start);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_diff(&delta,_gp,links[_li].pcm_start));
if(delta<links[_li].head.pre_skip)delta=0;
else delta-=links[_li].head.pre_skip;
pcm_offset+=delta;
@@ -2379,14 +2362,12 @@
ogg_int64_t op_pcm_tell(OggOpusFile *_of){
ogg_int64_t gp;
int nbuffered;
- int ret;
int li;
if(OP_UNLIKELY(_of->ready_state<OP_OPENED))return OP_EINVAL;
gp=_of->prev_packet_gp;
if(gp==-1)return 0;
nbuffered=OP_MAX(_of->od_buffer_size-_of->od_buffer_pos,0);
- ret=op_granpos_add(&gp,gp,-nbuffered);
- OP_ASSERT(!ret);
+ OP_ALWAYS_TRUE(!op_granpos_add(&gp,gp,-nbuffered));
li=_of->seekable?_of->cur_link:0;
if(op_granpos_add(&gp,gp,_of->cur_discard_count)<0){
gp=_of->links[li].pcm_end;