From e082c2c3dfced1cd20d7c1cb7ee7a661dffc8686 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 21 Nov 2014 09:58:09 +0100 Subject: Remove some unneeded NULL checks Found by Coverity; also see commit 85fb2af3. --- audio/filter/af_export.c | 11 ++++++----- input/keycodes.c | 2 +- options/m_option.c | 29 +++++++++++++---------------- stream/rar.c | 5 ++--- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/audio/filter/af_export.c b/audio/filter/af_export.c index 9c3bab671a..d867bc4a94 100644 --- a/audio/filter/af_export.c +++ b/audio/filter/af_export.c @@ -78,8 +78,7 @@ static int control(struct af_instance* af, int cmd, void* arg) int mapsize; // Free previous buffers - if (s->buf) - free(s->buf[0]); + free(s->buf[0]); // unmap previous area if(s->mmap_area) @@ -94,8 +93,10 @@ static int control(struct af_instance* af, int cmd, void* arg) // Allocate new buffers (as one continuous block) s->buf[0] = calloc(s->sz*af->data->nch, af->data->bps); - if(NULL == s->buf[0]) + if(NULL == s->buf[0]) { MP_FATAL(af, "Out of memory\n"); + return AF_ERROR; + } for(i = 1; i < af->data->nch; i++) s->buf[i] = (uint8_t *)s->buf[0] + i*s->sz*af->data->bps; @@ -147,8 +148,8 @@ static int control(struct af_instance* af, int cmd, void* arg) static void uninit( struct af_instance* af ) { af_export_t* s = af->priv; - if (s->buf) - free(s->buf[0]); + + free(s->buf[0]); // Free mmaped area if(s->mmap_area) diff --git a/input/keycodes.c b/input/keycodes.c index 5108a8beae..e5ca0bf77d 100644 --- a/input/keycodes.c +++ b/input/keycodes.c @@ -305,7 +305,7 @@ int mp_input_get_keys_from_string(char *name, int max_num_keys, ptr = name; n = 0; - for (end = strchr(ptr, '-'); ptr != NULL; end = strchr(ptr, '-')) { + for (end = strchr(ptr, '-'); ; end = strchr(ptr, '-')) { if (end && end[1] != '\0') { if (end[1] == '-') end = &end[1]; diff --git a/options/m_option.c b/options/m_option.c index 9ec6ccc427..ce86db0696 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2288,23 +2288,20 @@ bool m_obj_list_find(struct m_obj_desc *dst, const struct m_obj_list *l, if (bstr_equals0(name, dst->name)) return true; } - if (l->aliases) { - for (int i = 0; l->aliases[i][0]; i++) { - const char *aname = l->aliases[i][0]; - const char *alias = l->aliases[i][1]; - const char *opts = l->aliases[i][2]; - if (bstr_equals0(name, aname) && - m_obj_list_find(dst, l, bstr0(alias))) - { - if (opts) { - dst->init_options = opts; - } else { - // Assume it's deprecated in this case. - // Also, it's used by the VO code only, so whatever. - dst->replaced_name = aname; - } - return true; + for (int i = 0; l->aliases[i][0]; i++) { + const char *aname = l->aliases[i][0]; + const char *alias = l->aliases[i][1]; + const char *opts = l->aliases[i][2]; + if (bstr_equals0(name, aname) && m_obj_list_find(dst, l, bstr0(alias))) + { + if (opts) { + dst->init_options = opts; + } else { + // Assume it's deprecated in this case. + // Also, it's used by the VO code only, so whatever. + dst->replaced_name = aname; } + return true; } } return false; diff --git a/stream/rar.c b/stream/rar.c index 12d3b0bfd7..7fae5e35ac 100644 --- a/stream/rar.c +++ b/stream/rar.c @@ -438,13 +438,12 @@ ssize_t RarRead(rar_file_t *file, void *data, size_t size) if (max <= 0) break; - int r = file->s ? stream_read(file->s, data, max) : -1; + int r = stream_read(file->s, data, max); if (r <= 0) break; total += r; - if( data ) - data = (char *)data + r; + data = (char *)data + r; file->i_pos += r; if (file->i_pos >= chunk_end && RarSeek(file, file->i_pos)) -- cgit v1.2.3