Coverity fixes

Signed-off-by: Felipe Contreras <felipe.contreras@nokia.com>
This commit is contained in:
Felipe Contreras 2011-04-28 20:43:21 +03:00 committed by David Schleef
parent c2593cc1bd
commit 6c8d740c1a
4 changed files with 27 additions and 15 deletions

View File

@ -259,7 +259,7 @@ void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
byteSwap(ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
if(0 != ctx->internal_buf) {
free(ctx->internal_buf);
ctx->internal_buf = 0;
@ -408,7 +408,8 @@ FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const
if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
return false;
}
ctx->internal_buf = tmp;
else
ctx->internal_buf = tmp;
ctx->capacity = bytes_needed;
}

View File

@ -1217,6 +1217,7 @@ static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle han
}
if(!read_metadata_block_header_cb_(handle, read_cb, &is_last, &type, &length)) {
node_delete_(node);
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
return false;
}
@ -1411,38 +1412,34 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t
}
if(!open_tempfile_(chain->filename, tempfile_path_prefix, &tempfile, &tempfilename, &status)) {
chain->status = get_equivalent_status_(status);
cleanup_tempfile_(&tempfile, &tempfilename);
return false;
goto err;
}
if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) {
chain->status = get_equivalent_status_(status);
cleanup_tempfile_(&tempfile, &tempfilename);
return false;
goto err;
}
/* write the metadata */
for(node = chain->head; node; node = node->next) {
if(!write_metadata_block_header_(tempfile, &status, node->data)) {
chain->status = get_equivalent_status_(status);
return false;
goto err;
}
if(!write_metadata_block_data_(tempfile, &status, node->data)) {
chain->status = get_equivalent_status_(status);
return false;
goto err;
}
}
/*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/
/* copy the file postfix (everything after the metadata) */
if(0 != fseeko(f, chain->last_offset, SEEK_SET)) {
cleanup_tempfile_(&tempfile, &tempfilename);
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
goto err;
}
if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) {
cleanup_tempfile_(&tempfile, &tempfilename);
chain->status = get_equivalent_status_(status);
return false;
goto err;
}
/* move the tempfile on top of the original */
@ -1451,6 +1448,11 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t
return false;
return true;
err:
(void)fclose(f);
cleanup_tempfile_(&tempfile, &tempfilename);
return false;
}
/* assumes 'handle' is already at beginning of file */

View File

@ -287,8 +287,10 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con
*error_message = 0;
if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE)))
if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE))) {
*error_message = error_messages[0];
return obj;
}
if(strchr(spec, '|')) { /* full format */
const char *p;
@ -363,8 +365,10 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con
*error_message = error_messages[0];
else {
FILE *f = fopen(spec, "rb");
if(0 == f)
if(0 == f) {
*error_message = error_messages[5];
free(buffer);
}
else {
if(fread(buffer, 1, size, f) != (size_t)size)
*error_message = error_messages[6];
@ -379,6 +383,9 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con
else if((obj->data.picture.width == 0 || obj->data.picture.height == 0 || obj->data.picture.depth == 0) && !local__extract_resolution_color_info_(&obj->data.picture))
*error_message = error_messages[4];
}
else {
free(buffer);
}
}
}
}

View File

@ -505,8 +505,10 @@ static const char *store_to_file_post_(const char *filename, FLAC__Metadata_Chai
FLAC__metadata_chain_sort_padding(chain);
if(!FLAC__metadata_chain_write(chain, /*use_padding=*/true, preserve_modtime)) {
const char *error;
error = FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)];
FLAC__metadata_chain_delete(chain);
return FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)];
return error;
}
FLAC__metadata_chain_delete(chain);