More static code analysis nits

This commit is contained in:
twinaphex 2015-09-28 18:44:28 +02:00
parent 631da50dfa
commit 0cc56e2a1a
17 changed files with 83 additions and 76 deletions

View File

@ -66,7 +66,7 @@ static unsigned bitswap(unsigned i, unsigned range)
unsigned ret = 0; unsigned ret = 0;
for (shifts = 0; shifts < range; shifts++) for (shifts = 0; shifts < range; shifts++)
ret |= i & (1 << (range - shifts - 1)) ? (1 << shifts) : 0; ret |= (i & (1 << (range - shifts - 1))) ? (1 << shifts) : 0;
return ret; return ret;
} }

View File

@ -75,7 +75,7 @@ static void autosave_thread(void *data)
while (!save->quit) while (!save->quit)
{ {
bool differ = false; bool differ;
autosave_lock(save); autosave_lock(save);
differ = memcmp(save->buffer, save->retro_buffer, differ = memcmp(save->buffer, save->retro_buffer,

View File

@ -331,7 +331,7 @@ void save_ram_file(const char *path, int type)
if (!data) if (!data)
return; return;
if (size <= 0) if (size == 0)
return; return;
if (!retro_write_file(path, data, size)) if (!retro_write_file(path, data, size))

View File

@ -201,10 +201,10 @@ static int read_7zip_file(
SRes res; SRes res;
ISzAlloc allocImp; ISzAlloc allocImp;
ISzAlloc allocTempImp; ISzAlloc allocTempImp;
uint8_t *outBuffer = 0; uint8_t *output = 0;
size_t outBufferSize = 0; size_t output_size = 0;
uint16_t *temp = NULL; uint16_t *temp = NULL;
size_t tempSize = 0; size_t temp_size = 0;
long outsize = -1; long outsize = -1;
bool file_found = false; bool file_found = false;
@ -254,11 +254,11 @@ static int read_7zip_file(
len = SzArEx_GetFileNameUtf16(&db, i, NULL); len = SzArEx_GetFileNameUtf16(&db, i, NULL);
if (len > tempSize) if (len > temp_size)
{ {
free(temp); free(temp);
tempSize = len; temp_size = len;
temp = (uint16_t *)malloc(tempSize * sizeof(temp[0])); temp = (uint16_t *)malloc(temp_size * sizeof(temp[0]));
if (temp == 0) if (temp == 0)
{ {
res = SZ_ERROR_MEM; res = SZ_ERROR_MEM;
@ -276,7 +276,7 @@ static int read_7zip_file(
* */ * */
file_found = true; file_found = true;
res = SzArEx_Extract(&db, &lookStream.s, i,&blockIndex, res = SzArEx_Extract(&db, &lookStream.s, i,&blockIndex,
&outBuffer, &outBufferSize,&offset, &outSizeProcessed, &output, &output_size, &offset, &outSizeProcessed,
&allocImp, &allocTempImp); &allocImp, &allocTempImp);
if (res != SZ_OK) if (res != SZ_OK)
@ -286,7 +286,7 @@ static int read_7zip_file(
if (optional_outfile != NULL) if (optional_outfile != NULL)
{ {
const void *ptr = (const void*)(outBuffer + offset); const void *ptr = (const void*)(output + offset);
if (!retro_write_file(optional_outfile, ptr, outsize)) if (!retro_write_file(optional_outfile, ptr, outsize))
{ {
@ -307,14 +307,14 @@ static int read_7zip_file(
* copy and free the old one. */ * copy and free the old one. */
*buf = malloc(outsize + 1); *buf = malloc(outsize + 1);
((char*)(*buf))[outsize] = '\0'; ((char*)(*buf))[outsize] = '\0';
memcpy(*buf,outBuffer+offset,outsize); memcpy(*buf,output + offset,outsize);
} }
break; break;
} }
} }
} }
IAlloc_Free(&allocImp, outBuffer); IAlloc_Free(&allocImp, output);
SzArEx_Free(&db, &allocImp); SzArEx_Free(&db, &allocImp);
free(temp); free(temp);
File_Close(&archiveStream.file); File_Close(&archiveStream.file);
@ -346,7 +346,7 @@ static struct string_list *compressed_7zip_file_list_new(
ISzAlloc allocImp; ISzAlloc allocImp;
ISzAlloc allocTempImp; ISzAlloc allocTempImp;
uint16_t *temp = NULL; uint16_t *temp = NULL;
size_t tempSize = 0; size_t temp_size = 0;
long outsize = -1; long outsize = -1;
struct string_list *ext_list = NULL; struct string_list *ext_list = NULL;
@ -384,13 +384,6 @@ static struct string_list *compressed_7zip_file_list_new(
if (res == SZ_OK) if (res == SZ_OK)
{ {
uint32_t i; uint32_t i;
uint32_t blockIndex = 0xFFFFFFFF;
uint8_t *outBuffer = 0;
size_t outBufferSize = 0;
(void)blockIndex;
(void)outBufferSize;
(void)outBuffer;
for (i = 0; i < db.db.NumFiles; i++) for (i = 0; i < db.db.NumFiles; i++)
{ {
@ -412,11 +405,11 @@ static struct string_list *compressed_7zip_file_list_new(
len = SzArEx_GetFileNameUtf16(&db, i, NULL); len = SzArEx_GetFileNameUtf16(&db, i, NULL);
if (len > tempSize) if (len > temp_size)
{ {
free(temp); free(temp);
tempSize = len; temp_size = len;
temp = (uint16_t *)malloc(tempSize * sizeof(temp[0])); temp = (uint16_t *)malloc(temp_size * sizeof(temp[0]));
if (temp == 0) if (temp == 0)
{ {

View File

@ -2980,7 +2980,6 @@ error:
static void* gl_read_frame_raw(void *data, unsigned *width_p, static void* gl_read_frame_raw(void *data, unsigned *width_p,
unsigned *height_p, size_t *pitch_p) unsigned *height_p, size_t *pitch_p)
{ {
int i;
gl_t *gl = (gl_t*)data; gl_t *gl = (gl_t*)data;
unsigned width = gl->last_width[gl->tex_index]; unsigned width = gl->last_width[gl->tex_index];
unsigned height = gl->last_height[gl->tex_index]; unsigned height = gl->last_height[gl->tex_index];
@ -3019,6 +3018,8 @@ unsigned *height_p, size_t *pitch_p)
#ifdef HAVE_FBO #ifdef HAVE_FBO
if (gl->hw_render_use) if (gl->hw_render_use)
{ {
unsigned i;
for(i = 0; i < height ; i++) for(i = 0; i < height ; i++)
memcpy((uint8_t*)buffer + i * pitch, memcpy((uint8_t*)buffer + i * pitch,
(uint8_t*)buffer_texture + (height - 1 - i) * pitch, pitch); (uint8_t*)buffer_texture + (height - 1 - i) * pitch, pitch);

View File

@ -106,7 +106,6 @@ static unsigned twoxbr_generic_threads(void *data)
static void SetupFormat(void * data) static void SetupFormat(void * data)
{ {
uint16_t r, g, b, y, u, v;
uint32_t c; uint32_t c;
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
@ -210,12 +209,12 @@ static void SetupFormat(void * data)
for (c = 0; c < 65536; c++) for (c = 0; c < 65536; c++)
{ {
r = filt->tbl_5_to_8[(c & RED_MASK565) >> 11]; uint16_t r = filt->tbl_5_to_8[(c & RED_MASK565) >> 11];
g = filt->tbl_6_to_8[(c & GREEN_MASK565) >> 5]; uint16_t g = filt->tbl_6_to_8[(c & GREEN_MASK565) >> 5];
b = filt->tbl_5_to_8[(c & BLUE_MASK565) ]; uint16_t b = filt->tbl_5_to_8[(c & BLUE_MASK565) ];
y = ((r << 4) + (g << 5) + (b << 2)); uint16_t y = ((r << 4) + (g << 5) + (b << 2));
u = ( -r - (g << 1) + (b << 2)); uint16_t u = ( -r - (g << 1) + (b << 2));
v = ((r << 1) - (g << 1) - (b >> 1)); uint16_t v = ((r << 1) - (g << 1) - (b >> 1));
filt->RGBtoYUV[c] = y + u + v; filt->RGBtoYUV[c] = y + u + v;
} }
} }

View File

@ -246,7 +246,6 @@ static void udev_handle_mouse(udev_input_t *udev,
else if (event->value == -1) else if (event->value == -1)
udev->mouse_whd = 1; udev->mouse_whd = 1;
break; break;
break;
default: default:
break; break;
} }

View File

@ -759,10 +759,8 @@ static int zlib_get_file_list_cb(const char *path, const char *valid_exts,
if (ext_list) if (ext_list)
{ {
char last_char = ' ';
/* Checks if this entry is a directory or a file. */ /* Checks if this entry is a directory or a file. */
last_char = path[strlen(path)-1]; char last_char = path[strlen(path)-1];
if (last_char == '/' || last_char == '\\' ) /* Skip if directory. */ if (last_char == '/' || last_char == '\\' ) /* Skip if directory. */
goto error; goto error;

View File

@ -154,7 +154,7 @@ bool path_contains_compressed_file(const char *path)
**/ **/
bool path_is_compressed_file(const char* path) bool path_is_compressed_file(const char* path)
{ {
#ifdef HAVE_COMPRESSION #if defined(HAVE_COMPRESSION) && (defined(HAVE_ZLIB) || defined(HAVE_7ZIP))
const char* file_ext = path_get_extension(path); const char* file_ext = path_get_extension(path);
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB

View File

@ -220,9 +220,9 @@ static bool png_process_ihdr(struct png_ihdr *ihdr)
#ifdef RPNG_TEST #ifdef RPNG_TEST
fprintf(stderr, "IHDR: (%u x %u), bpc = %u, palette = %s, color = %s, alpha = %s, adam7 = %s.\n", fprintf(stderr, "IHDR: (%u x %u), bpc = %u, palette = %s, color = %s, alpha = %s, adam7 = %s.\n",
ihdr->width, ihdr->height, ihdr->width, ihdr->height,
ihdr->depth, ihdr->color_type == PNG_IHDR_COLOR_PLT ? "yes" : "no", ihdr->depth, (ihdr->color_type == PNG_IHDR_COLOR_PLT) ? "yes" : "no",
ihdr->color_type & PNG_IHDR_COLOR_RGB ? "yes" : "no", (ihdr->color_type & PNG_IHDR_COLOR_RGB) ? "yes" : "no",
ihdr->color_type & PNG_IHDR_COLOR_GRAY_ALPHA ? "yes" : "no", (ihdr->color_type & PNG_IHDR_COLOR_GRAY_ALPHA) ? "yes" : "no",
ihdr->interlace == 1 ? "yes" : "no"); ihdr->interlace == 1 ? "yes" : "no");
#endif #endif

View File

@ -80,7 +80,6 @@ static void sha256_block(struct sha256_ctx *p)
unsigned i; unsigned i;
uint32_t s0, s1; uint32_t s0, s1;
uint32_t a, b, c, d, e, f, g, h; uint32_t a, b, c, d, e, f, g, h;
uint32_t t1, t2, maj, ch;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
p->w[i] = load32be(p->in.u32 + i); p->w[i] = load32be(p->in.u32 + i);
@ -97,6 +96,8 @@ static void sha256_block(struct sha256_ctx *p)
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
{ {
uint32_t t1, t2, maj, ch;
s0 = ROR32(a, 2) ^ ROR32(a, 13) ^ ROR32(a, 22); s0 = ROR32(a, 2) ^ ROR32(a, 13) ^ ROR32(a, 22);
maj = (a & b) ^ (a & c) ^ (b & c); maj = (a & b) ^ (a & c) ^ (b & c);
t2 = s0 + maj; t2 = s0 + maj;
@ -104,8 +105,14 @@ static void sha256_block(struct sha256_ctx *p)
ch = (e & f) ^ (~e & g); ch = (e & f) ^ (~e & g);
t1 = h + s1 + ch + T_K[i] + p->w[i]; t1 = h + s1 + ch + T_K[i] + p->w[i];
h = g; g = f; f = e; e = d + t1; h = g;
d = c; c = b; b = a; a = t1 + t2; g = f;
f = e;
e = d + t1;
d = c;
c = b;
b = a;
a = t1 + t2;
} }
p->h[0] += a; p->h[1] += b; p->h[2] += c; p->h[3] += d; p->h[0] += a; p->h[1] += b; p->h[2] += c; p->h[3] += d;
@ -118,14 +125,14 @@ static void sha256_block(struct sha256_ctx *p)
static void sha256_chunk(struct sha256_ctx *p, static void sha256_chunk(struct sha256_ctx *p,
const uint8_t *s, unsigned len) const uint8_t *s, unsigned len)
{ {
unsigned l;
p->len += len; p->len += len;
while (len) while (len)
{ {
l = 64 - p->inlen; unsigned l = 64 - p->inlen;
l = (len < l) ? len : l;
if (len < l)
l = len;
memcpy(p->in.u8 + p->inlen, s, l); memcpy(p->in.u8 + p->inlen, s, l);

View File

@ -262,7 +262,6 @@ static void rmenu_wallpaper_set_defaults(char *s, size_t len)
static void rmenu_context_reset(void) static void rmenu_context_reset(void)
{ {
unsigned fb_width, fb_height;
char menu_bg[PATH_MAX_LENGTH] = {0}; char menu_bg[PATH_MAX_LENGTH] = {0};
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();

View File

@ -2324,16 +2324,17 @@ static void xmb_list_clear(file_list_t *list)
static void xmb_list_deep_copy(menu_handle_t *menu, const file_list_t *src, file_list_t *dst) static void xmb_list_deep_copy(menu_handle_t *menu, const file_list_t *src, file_list_t *dst)
{ {
size_t size, i; size_t i;
size_t size = dst->size;
size = dst->size;
for (i = 0; i < size; ++i) for (i = 0; i < size; ++i)
{ {
float *subjects[5];
xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(dst, i); xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(dst, i);
if (node) if (node)
{ {
float *subjects[5];
subjects[0] = &node->alpha; subjects[0] = &node->alpha;
subjects[1] = &node->label_alpha; subjects[1] = &node->label_alpha;
subjects[2] = &node->zoom; subjects[2] = &node->zoom;
@ -2350,6 +2351,7 @@ static void xmb_list_deep_copy(menu_handle_t *menu, const file_list_t *src, file
file_list_copy(src, dst); file_list_copy(src, dst);
size = dst->size; size = dst->size;
for (i = 0; i < size; ++i) for (i = 0; i < size; ++i)
{ {
void *src_udata = file_list_get_userdata_at_offset(src, i); void *src_udata = file_list_get_userdata_at_offset(src, i);

View File

@ -936,7 +936,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
list_size = content_playlist_size(playlist); list_size = content_playlist_size(playlist);
if (list_size <= 0) if (list_size == 0)
{ {
menu_list_push(info->list, menu_list_push(info->list,
menu_hash_to_str(MENU_LABEL_VALUE_NO_PLAYLIST_ENTRIES_AVAILABLE), menu_hash_to_str(MENU_LABEL_VALUE_NO_PLAYLIST_ENTRIES_AVAILABLE),
@ -1525,7 +1525,7 @@ static int deferred_push_video_shader_parameters_common(
unsigned i; unsigned i;
size_t list_size = shader->num_parameters; size_t list_size = shader->num_parameters;
if (list_size <= 0) if (list_size == 0)
{ {
menu_list_push(info->list, menu_list_push(info->list,
menu_hash_to_str(MENU_LABEL_VALUE_NO_SHADER_PARAMETERS), menu_hash_to_str(MENU_LABEL_VALUE_NO_SHADER_PARAMETERS),
@ -2207,7 +2207,7 @@ static int menu_displaylist_parse_generic(menu_displaylist_info_t *info, bool *n
list_size = str_list->size; list_size = str_list->size;
if (list_size <= 0) if (list_size == 0)
{ {
if (!(info->flags & SL_FLAG_ALLOW_EMPTY_LIST)) if (!(info->flags & SL_FLAG_ALLOW_EMPTY_LIST))
{ {

View File

@ -350,10 +350,12 @@ void menu_input_st_hex_callback(void *userdata, const char *str)
setting = menu_setting_find(label); setting = menu_setting_find(label);
if (setting) if (setting)
{
if (str[0] == '#') if (str[0] == '#')
str++; str++;
*setting->value.unsigned_integer = strtoul(str, NULL, 16); *setting->value.unsigned_integer = strtoul(str, NULL, 16);
} }
}
menu_input_key_end_line(); menu_input_key_end_line();
} }

View File

@ -55,7 +55,6 @@ static void menu_settings_info_list_free(rarch_setting_info_t *list_info)
{ {
if (list_info) if (list_info)
free(list_info); free(list_info);
list_info = NULL;
} }
static bool menu_settings_list_append(rarch_setting_t **list, static bool menu_settings_list_append(rarch_setting_t **list,
@ -668,7 +667,7 @@ static int setting_action_start_analog_dpad_mode(void *data)
static int setting_action_start_libretro_device_type(void *data) static int setting_action_start_libretro_device_type(void *data)
{ {
unsigned current_device, i, devices[128], types = 0, port = 0; unsigned current_device, devices[128], types = 0, port = 0;
const struct retro_controller_info *desc = NULL; const struct retro_controller_info *desc = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data; rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -692,6 +691,8 @@ static int setting_action_start_libretro_device_type(void *data)
if (desc) if (desc)
{ {
unsigned i;
for (i = 0; i < desc->num_types; i++) for (i = 0; i < desc->num_types; i++)
{ {
unsigned id = desc->types[i].id; unsigned id = desc->types[i].id;
@ -1690,17 +1691,19 @@ static void setting_get_string_representation_uint_user_language(void *data,
static void setting_get_string_representation_uint_libretro_log_level(void *data, static void setting_get_string_representation_uint_libretro_log_level(void *data,
char *s, size_t len) char *s, size_t len)
{ {
rarch_setting_t *setting = (rarch_setting_t*)data;
if (setting)
{
static const char *modes[] = { static const char *modes[] = {
"0 (Debug)", "0 (Debug)",
"1 (Info)", "1 (Info)",
"2 (Warning)", "2 (Warning)",
"3 (Error)" "3 (Error)"
}; };
rarch_setting_t *setting = (rarch_setting_t*)data;
if (setting)
strlcpy(s, modes[*setting->value.unsigned_integer], strlcpy(s, modes[*setting->value.unsigned_integer],
len); len);
}
} }
static void setting_get_string_representation_uint(void *data, static void setting_get_string_representation_uint(void *data,
@ -6600,6 +6603,7 @@ rarch_setting_t *menu_setting_new(unsigned mask)
goto error; goto error;
menu_settings_info_list_free(list_info); menu_settings_info_list_free(list_info);
list_info = NULL;
return list; return list;
@ -6608,6 +6612,8 @@ error:
menu_settings_info_list_free(list_info); menu_settings_info_list_free(list_info);
menu_setting_free(list); menu_setting_free(list);
list_info = NULL;
return NULL; return NULL;
} }

View File

@ -404,10 +404,11 @@ static int rarch_main_data_http_iterate_transfer(void *data)
{ {
http_handle_t *http = (http_handle_t*)data; http_handle_t *http = (http_handle_t*)data;
size_t pos = 0, tot = 0; size_t pos = 0, tot = 0;
int percent = 0;
if (!net_http_update(http->handle, &pos, &tot)) if (!net_http_update(http->handle, &pos, &tot))
{ {
int percent = 0;
if(tot != 0) if(tot != 0)
percent = (unsigned long long)pos * 100 percent = (unsigned long long)pos * 100
/ (unsigned long long)tot; / (unsigned long long)tot;