From 6f482ef4154113291c7bc55a51fe20193676879e Mon Sep 17 00:00:00 2001 From: "Timothy B. Terriberry" <tterribe@xiph.org> Date: Wed, 26 Mar 2014 16:44:28 -0700 Subject: [PATCH] Minor cleanups. Makes style slightly more consistent. Also fixes the return code of op_fetch_headers() to make it consistently return OP_EBADHEADER if the stream runs out of pages after a valid OpusHead packet is found. Previously, if a valid OpusHead was found, it would return OP_ENOTFORMAT if it ran out of pages before finding one without its BOS flag set, and OP_EBADHEADER if it ran out of pages after finding one without its BOS flag set. --- src/opusfile.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/opusfile.c b/src/opusfile.c index 2374bd2..1441b97 100644 --- a/src/opusfile.c +++ b/src/opusfile.c @@ -156,8 +156,8 @@ static int op_get_data(OggOpusFile *_of,int _nbytes){ /*Save a tiny smidge of verbosity to make the code more readable.*/ static int op_seek_helper(OggOpusFile *_of,opus_int64 _offset){ if(_offset==_of->offset)return 0; - if(_of->callbacks.seek==NULL|| - (*_of->callbacks.seek)(_of->source,_offset,SEEK_SET)){ + if(_of->callbacks.seek==NULL + ||(*_of->callbacks.seek)(_of->source,_offset,SEEK_SET)){ return OP_EREAD; } _of->offset=_offset; @@ -496,22 +496,20 @@ static int op_fetch_headers_impl(OggOpusFile *_of,OpusHead *_head, ogg_stream_pagein(&_of->os,_og); if(OP_LIKELY(ogg_stream_packetout(&_of->os,&op)>0)){ ret=opus_head_parse(_head,op.packet,op.bytes); - if(OP_UNLIKELY(ret<0)){ - /*If it's just a stream type we don't recognize, ignore it. - Everything else is fatal.*/ - if(ret!=OP_ENOTFORMAT)return ret; - } /*Found a valid Opus header. Continue setup.*/ - else _of->ready_state=OP_STREAMSET; + if(OP_LIKELY(ret>=0))_of->ready_state=OP_STREAMSET; + /*If it's just a stream type we don't recognize, ignore it. + Everything else is fatal.*/ + else if(ret!=OP_ENOTFORMAT)return ret; } } /*Get the next page. No need to clamp the boundary offset against _of->end, as all errors - become OP_ENOTFORMAT.*/ + become OP_ENOTFORMAT or OP_EBADHEADER.*/ if(OP_UNLIKELY(op_get_next_page(_of,_og, OP_ADV_OFFSET(_of->offset,OP_CHUNK_SIZE))<0)){ - return OP_ENOTFORMAT; + return _of->ready_state<OP_STREAMSET?OP_ENOTFORMAT:OP_EBADHEADER; } } if(OP_UNLIKELY(_of->ready_state!=OP_STREAMSET))return OP_ENOTFORMAT; -- GitLab