More static code analysis fixes

This commit is contained in:
twinaphex 2015-09-28 17:18:48 +02:00
parent b5456bc940
commit 1eb80f6c93
5 changed files with 31 additions and 18 deletions

View File

@ -201,6 +201,10 @@ int database_info_build_query(char *s, size_t len,
return 0;
}
/*
* NOTE: Allocates memory, it is the caller's responsibility to free the
* memory after it is no longer required.
*/
char *bin_to_hex_alloc(const uint8_t *data, size_t len)
{
size_t i;
@ -210,7 +214,7 @@ char *bin_to_hex_alloc(const uint8_t *data, size_t len)
return NULL;
for (i = 0; i < len; i++)
snprintf(ret+i*2, 3, "%02X", data[i]);
snprintf(ret+i * 2, 3, "%02X", data[i]);
return ret;
}

View File

@ -113,6 +113,10 @@ void database_info_free(database_info_handle_t *handle);
int database_info_build_query(
char *query, size_t len, const char *label, const char *path);
/*
* NOTE: Allocates memory, it is the caller's responsibility to free the
* memory after it is no longer required.
*/
char *bin_to_hex_alloc(const uint8_t *data, size_t len);
#ifdef __cplusplus

View File

@ -219,8 +219,8 @@ bool texture_image_load(struct texture_image *out_img, const char *path)
#else
bool texture_image_load(struct texture_image *out_img, const char *path)
{
bool ret = false;
unsigned r_shift, g_shift, b_shift, a_shift;
bool ret = false;
texture_image_set_color_shifts(&r_shift, &g_shift, &b_shift,
&a_shift);
@ -229,9 +229,9 @@ bool texture_image_load(struct texture_image *out_img, const char *path)
if (strstr(path, ".tga"))
{
ssize_t len;
void *raw_buf = NULL;
uint8_t *buf = NULL;
ssize_t len;
ret = read_file(path, &raw_buf, &len);
if (!ret || len < 0)

View File

@ -776,7 +776,7 @@ bool video_driver_overlay_interface(const video_overlay_interface_t **iface)
driver_t *driver = driver_get_ptr();
const video_driver_t *video = video_driver_ctx_get_ptr(driver);
if (video->overlay_interface)
if (video && video->overlay_interface)
{
video->overlay_interface(driver->video_data, iface);
return true;

View File

@ -407,11 +407,16 @@ static int database_info_iterate_serial_lookup(
if (db_state->entry_index == 0)
{
char query[50] = {0};
snprintf(query, sizeof(query), "{'serial': b'%s'}",
bin_to_hex_alloc((uint8_t*)db_state->serial, 10*sizeof(uint8_t)));
char query[50];
char *serial_buf = bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
if (!serial_buf)
return 1;
snprintf(query, sizeof(query), "{'serial': b'%s'}", serial_buf);
database_info_list_iterate_new(db_state, query);
free(serial_buf);
}
if (db_state->info)