Commit dfdb0b71 authored by giles's avatar giles

Move dereferences after null argument checks.

Problem reported by the Coverity static analysis tool.


git-svn-id: http://svn.annodex.net/liboggz/trunk@3787 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 60dedad8
......@@ -614,7 +614,7 @@ oggz_offset_end (OGGZ * oggz)
static ogg_int64_t
oggz_seek_set (OGGZ * oggz, ogg_int64_t unit_target)
{
OggzReader * reader = &oggz->x.reader;
OggzReader * reader;
oggz_off_t offset_orig, offset_at, offset_guess;
oggz_off_t offset_begin, offset_end = -1, offset_next;
ogg_int64_t granule_at;
......@@ -641,6 +641,8 @@ oggz_seek_set (OGGZ * oggz, ogg_int64_t unit_target)
return -1;
}
reader = &oggz->x.reader;
if (unit_target == reader->current_unit) {
#ifdef DEBUG
printf ("oggz_seek_set: unit_target == reader->current_unit, SKIP\n");
......@@ -823,7 +825,7 @@ oggz_seek_end (OGGZ * oggz, ogg_int64_t unit_offset)
off_t
oggz_seek (OGGZ * oggz, oggz_off_t offset, int whence)
{
OggzReader * reader = &oggz->x.reader;
OggzReader * reader;
ogg_int64_t units = -1;
if (oggz == NULL) return -1;
......@@ -833,7 +835,9 @@ oggz_seek (OGGZ * oggz, oggz_off_t offset, int whence)
}
if (offset == 0 && whence == SEEK_SET) units = 0;
reader = &oggz->x.reader;
if (!(offset == 0 && whence == SEEK_CUR)) {
/* Invalidate current_unit */
reader->current_unit = -1;
......@@ -845,7 +849,7 @@ oggz_seek (OGGZ * oggz, oggz_off_t offset, int whence)
ogg_int64_t
oggz_seek_units (OGGZ * oggz, ogg_int64_t units, int whence)
{
OggzReader * reader = &oggz->x.reader;
OggzReader * reader;
ogg_int64_t r;
......@@ -870,6 +874,8 @@ oggz_seek_units (OGGZ * oggz, ogg_int64_t units, int whence)
return -1;
}
reader = &oggz->x.reader;
switch (whence) {
case SEEK_SET:
r = oggz_seek_set (oggz, units);
......
......@@ -373,13 +373,14 @@ oggz_write_feed (OGGZ * oggz, ogg_packet * op, long serialno, int flush,
static long
oggz_page_init (OGGZ * oggz)
{
OggzWriter * writer = &oggz->x.writer;
OggzWriter * writer;
ogg_stream_state * os;
ogg_page * og;
int ret;
if (oggz == NULL) return -1;
writer = &oggz->x.writer;
os = writer->current_stream;
og = &oggz->current_page;
......@@ -414,13 +415,14 @@ oggz_page_init (OGGZ * oggz)
static long
oggz_packet_init (OGGZ * oggz, oggz_writer_packet_t * next_zpacket)
{
OggzWriter * writer = &oggz->x.writer;
OggzWriter * writer;
oggz_stream_t * stream;
ogg_stream_state * os;
ogg_packet * op;
if (oggz == NULL) return -1L;
writer = &oggz->x.writer;
writer->current_zpacket = next_zpacket;
op = &next_zpacket->op;
......@@ -449,12 +451,13 @@ oggz_packet_init (OGGZ * oggz, oggz_writer_packet_t * next_zpacket)
static long
oggz_page_copyout (OGGZ * oggz, unsigned char * buf, long n)
{
OggzWriter * writer = &oggz->x.writer;
OggzWriter * writer;
long h, b;
ogg_page * og;
if (oggz == NULL) return -1L;
writer = &oggz->x.writer;
og = &oggz->current_page;
h = MIN (n, og->header_len - writer->page_offset);
......@@ -491,7 +494,7 @@ oggz_page_copyout (OGGZ * oggz, unsigned char * buf, long n)
static long
oggz_page_writeout (OGGZ * oggz, long n)
{
OggzWriter * writer = &oggz->x.writer;
OggzWriter * writer;
long h, b, nwritten;
ogg_page * og;
......@@ -501,6 +504,7 @@ oggz_page_writeout (OGGZ * oggz, long n)
if (oggz == NULL) return -1L;
writer = &oggz->x.writer;
og = &oggz->current_page;
#ifdef OGGZ_WRITE_DIRECT
......@@ -901,11 +905,13 @@ oggz_write (OGGZ * oggz, long n)
long
oggz_write_get_next_page_size (OGGZ * oggz)
{
OggzWriter * writer = &oggz->x.writer;
OggzWriter * writer;
ogg_page * og;
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
writer = &oggz->x.writer;
if (!(oggz->flags & OGGZ_WRITE)) {
return OGGZ_ERR_INVALID;
}
......
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