(libretro-common) Cleanups

This commit is contained in:
twinaphex 2015-06-13 00:33:31 +02:00
parent b31723236d
commit cdec12faa5
9 changed files with 78 additions and 65 deletions

View File

@ -84,7 +84,8 @@ static char *getaline(FILE *file)
static char *extract_value(char *line, bool is_value) static char *extract_value(char *line, bool is_value)
{ {
char *save = NULL, *tok = NULL; char *save = NULL;
char *tok = NULL;
if (is_value) if (is_value)
{ {
@ -187,9 +188,10 @@ static void add_include_list(config_file_t *conf, const char *path)
static void add_sub_conf(config_file_t *conf, char *line) static void add_sub_conf(config_file_t *conf, char *line)
{ {
char real_path[PATH_MAX_LENGTH]; char real_path[PATH_MAX_LENGTH] = {0};
config_file_t *sub_conf = NULL; config_file_t *sub_conf = NULL;
char *path = extract_value(line, false); char *path = extract_value(line, false);
if (!path) if (!path)
return; return;
@ -268,9 +270,9 @@ static char *strip_comment(char *str)
static bool parse_line(config_file_t *conf, static bool parse_line(config_file_t *conf,
struct config_entry_list *list, char *line) struct config_entry_list *list, char *line)
{ {
char* comment = NULL; char *comment = NULL;
char* key = (char*)malloc(9); char *key = (char*)malloc(9);
char* key_tmp = NULL; char *key_tmp = NULL;
size_t cur_size = 8; size_t cur_size = 8;
size_t idx = 0; size_t idx = 0;
@ -780,7 +782,7 @@ void config_set_path(config_file_t *conf, const char *entry, const char *val)
#if defined(RARCH_CONSOLE) #if defined(RARCH_CONSOLE)
config_set_string(conf, entry, val); config_set_string(conf, entry, val);
#else #else
char buf[PATH_MAX_LENGTH]; char buf[PATH_MAX_LENGTH] = {0};
fill_pathname_abbreviate_special(buf, val, sizeof(buf)); fill_pathname_abbreviate_special(buf, val, sizeof(buf));
config_set_string(conf, entry, buf); config_set_string(conf, entry, buf);
#endif #endif
@ -788,7 +790,7 @@ void config_set_path(config_file_t *conf, const char *entry, const char *val)
void config_set_double(config_file_t *conf, const char *key, double val) void config_set_double(config_file_t *conf, const char *key, double val)
{ {
char buf[128]; char buf[128] = {0};
#ifdef __cplusplus #ifdef __cplusplus
snprintf(buf, sizeof(buf), "%f", (float)val); snprintf(buf, sizeof(buf), "%f", (float)val);
#else #else
@ -799,28 +801,28 @@ void config_set_double(config_file_t *conf, const char *key, double val)
void config_set_float(config_file_t *conf, const char *key, float val) void config_set_float(config_file_t *conf, const char *key, float val)
{ {
char buf[128]; char buf[128] = {0};
snprintf(buf, sizeof(buf), "%f", val); snprintf(buf, sizeof(buf), "%f", val);
config_set_string(conf, key, buf); config_set_string(conf, key, buf);
} }
void config_set_int(config_file_t *conf, const char *key, int val) void config_set_int(config_file_t *conf, const char *key, int val)
{ {
char buf[128]; char buf[128] = {0};
snprintf(buf, sizeof(buf), "%d", val); snprintf(buf, sizeof(buf), "%d", val);
config_set_string(conf, key, buf); config_set_string(conf, key, buf);
} }
void config_set_hex(config_file_t *conf, const char *key, unsigned val) void config_set_hex(config_file_t *conf, const char *key, unsigned val)
{ {
char buf[128]; char buf[128] = {0};
snprintf(buf, sizeof(buf), "%x", val); snprintf(buf, sizeof(buf), "%x", val);
config_set_string(conf, key, buf); config_set_string(conf, key, buf);
} }
void config_set_uint64(config_file_t *conf, const char *key, uint64_t val) void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
{ {
char buf[128]; char buf[128] = {0};
#ifdef _WIN32 #ifdef _WIN32
snprintf(buf, sizeof(buf), "%I64u", val); snprintf(buf, sizeof(buf), "%I64u", val);
#else #else
@ -831,7 +833,7 @@ void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
void config_set_char(config_file_t *conf, const char *key, char val) void config_set_char(config_file_t *conf, const char *key, char val)
{ {
char buf[2]; char buf[2] = {0};
snprintf(buf, sizeof(buf), "%c", val); snprintf(buf, sizeof(buf), "%c", val);
config_set_string(conf, key, buf); config_set_string(conf, key, buf);
} }
@ -899,6 +901,7 @@ bool config_get_entry_list_head(config_file_t *conf,
struct config_file_entry *entry) struct config_file_entry *entry)
{ {
const struct config_entry_list *head = conf->entries; const struct config_entry_list *head = conf->entries;
if (!head) if (!head)
return false; return false;
@ -911,6 +914,7 @@ bool config_get_entry_list_head(config_file_t *conf,
bool config_get_entry_list_next(struct config_file_entry *entry) bool config_get_entry_list_next(struct config_file_entry *entry)
{ {
const struct config_entry_list *next = entry->next; const struct config_entry_list *next = entry->next;
if (!next) if (!next)
return false; return false;

View File

@ -204,8 +204,6 @@ static int parse_dir_entry(const char *name, char *file_path,
struct string_list *dir_list_new(const char *dir, struct string_list *dir_list_new(const char *dir,
const char *ext, bool include_dirs) const char *ext, bool include_dirs)
{ {
char path_buf[PATH_MAX_LENGTH];
struct string_list *ext_list, *list;
#ifdef _WIN32 #ifdef _WIN32
WIN32_FIND_DATA ffd; WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE; HANDLE hFind = INVALID_HANDLE_VALUE;
@ -213,8 +211,10 @@ struct string_list *dir_list_new(const char *dir,
DIR *directory = NULL; DIR *directory = NULL;
const struct dirent *entry = NULL; const struct dirent *entry = NULL;
#endif #endif
char path_buf[PATH_MAX_LENGTH] = {0};
struct string_list *ext_list = NULL;
struct string_list *list = NULL;
ext_list = NULL;
(void)path_buf; (void)path_buf;
if (!(list = string_list_new())) if (!(list = string_list_new()))
@ -233,7 +233,7 @@ struct string_list *dir_list_new(const char *dir,
do do
{ {
int ret = 0; int ret = 0;
char file_path[PATH_MAX_LENGTH]; char file_path[PATH_MAX_LENGTH] = {0};
const char *name = ffd.cFileName; const char *name = ffd.cFileName;
const char *file_ext = path_get_extension(name); const char *file_ext = path_get_extension(name);
bool is_dir = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; bool is_dir = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
@ -265,7 +265,7 @@ error:
while ((entry = readdir(directory))) while ((entry = readdir(directory)))
{ {
int ret = 0; int ret = 0;
char file_path[PATH_MAX_LENGTH]; char file_path[PATH_MAX_LENGTH] = {0};
const char *name = entry->d_name; const char *name = entry->d_name;
const char *file_ext = path_get_extension(name); const char *file_ext = path_get_extension(name);
bool is_dir = false; bool is_dir = false;

View File

@ -688,7 +688,7 @@ static int zip_extract_cb(const char *name, const char *valid_exts,
if (ext && string_list_find_elem(data->ext, ext)) if (ext && string_list_find_elem(data->ext, ext))
{ {
char new_path[PATH_MAX_LENGTH]; char new_path[PATH_MAX_LENGTH] = {0};
if (data->extraction_directory) if (data->extraction_directory)
fill_pathname_join(new_path, data->extraction_directory, fill_pathname_join(new_path, data->extraction_directory,

View File

@ -212,8 +212,8 @@ bool path_file_exists(const char *path)
void fill_pathname(char *out_path, const char *in_path, void fill_pathname(char *out_path, const char *in_path,
const char *replace, size_t size) const char *replace, size_t size)
{ {
char tmp_path[PATH_MAX_LENGTH]; char tmp_path[PATH_MAX_LENGTH] = {0};
char *tok; char *tok = NULL;
rarch_assert(strlcpy(tmp_path, in_path, rarch_assert(strlcpy(tmp_path, in_path,
sizeof(tmp_path)) < sizeof(tmp_path)); sizeof(tmp_path)) < sizeof(tmp_path));
@ -302,6 +302,7 @@ void fill_pathname_dir(char *in_dir, const char *in_basename,
const char *replace, size_t size) const char *replace, size_t size)
{ {
const char *base = NULL; const char *base = NULL;
fill_pathname_slash(in_dir, size); fill_pathname_slash(in_dir, size);
base = path_basename(in_basename); base = path_basename(in_basename);
rarch_assert(strlcat(in_dir, base, size) < size); rarch_assert(strlcat(in_dir, base, size) < size);
@ -318,8 +319,11 @@ void fill_pathname_dir(char *in_dir, const char *in_basename,
**/ **/
void fill_pathname_base(char *out, const char *in_path, size_t size) void fill_pathname_base(char *out, const char *in_path, size_t size)
{ {
const char *ptr_bak = NULL;
const char *ptr = find_last_slash(in_path); const char *ptr = find_last_slash(in_path);
(void)ptr_bak;
if (ptr) if (ptr)
ptr++; ptr++;
else else
@ -332,8 +336,7 @@ void fill_pathname_base(char *out, const char *in_path, size_t size)
* /path/to/archive.7z#folder/mygame.img * /path/to/archive.7z#folder/mygame.img
* basename would be mygame.img in both cases * basename would be mygame.img in both cases
*/ */
ptr_bak = ptr;
const char *ptr_bak = ptr;
ptr = strchr(ptr_bak,'#'); ptr = strchr(ptr_bak,'#');
if (ptr) if (ptr)
ptr++; ptr++;
@ -453,11 +456,15 @@ void path_parent_dir(char *path)
**/ **/
const char *path_basename(const char *path) const char *path_basename(const char *path)
{ {
const char *last_hash = NULL;
const char *last = find_last_slash(path); const char *last = find_last_slash(path);
(void)last_hash;
#ifdef HAVE_COMPRESSION #ifdef HAVE_COMPRESSION
/* We cut either at the last hash or the last slash; whichever comes last */ /* We cut either at the last hash or the last slash; whichever comes last */
const char *last_hash = strchr(path,'#'); last_hash = strchr(path,'#');
if (last_hash > last) if (last_hash > last)
return last_hash + 1; return last_hash + 1;
#endif #endif
@ -497,7 +504,8 @@ bool path_is_absolute(const char *path)
void path_resolve_realpath(char *buf, size_t size) void path_resolve_realpath(char *buf, size_t size)
{ {
#ifndef RARCH_CONSOLE #ifndef RARCH_CONSOLE
char tmp[PATH_MAX_LENGTH]; char tmp[PATH_MAX_LENGTH] = {0};
strlcpy(tmp, buf, sizeof(tmp)); strlcpy(tmp, buf, sizeof(tmp));
#ifdef _WIN32 #ifdef _WIN32
@ -682,7 +690,9 @@ void fill_pathname_join_delim(char *out_path, const char *dir,
void fill_short_pathname_representation(char* out_rep, void fill_short_pathname_representation(char* out_rep,
const char *in_path, size_t size) const char *in_path, size_t size)
{ {
char path_short[PATH_MAX_LENGTH], *last_hash = NULL; char path_short[PATH_MAX_LENGTH] = {0};
char *last_hash = NULL;
fill_pathname(path_short, path_basename(in_path), "", fill_pathname(path_short, path_basename(in_path), "",
sizeof(path_short)); sizeof(path_short));

View File

@ -221,7 +221,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
{ {
long pos, file_len; long pos, file_len;
FILE *file; FILE *file;
char header[8]; char header[8] = {0};
struct rpng_t rpng = {{0}}; struct rpng_t rpng = {{0}};
bool ret = true; bool ret = true;
int retval = 0; int retval = 0;

View File

@ -233,7 +233,7 @@ void rpng_nbio_load_image_free(struct rpng_t *rpng)
bool rpng_nbio_load_image_argb_start(struct rpng_t *rpng) bool rpng_nbio_load_image_argb_start(struct rpng_t *rpng)
{ {
unsigned i; unsigned i;
char header[8]; char header[8] = {0};
if (!rpng) if (!rpng)
return false; return false;

View File

@ -27,7 +27,7 @@ bool rtga_image_load_shift(uint8_t *buf,
unsigned g_shift, unsigned b_shift) unsigned g_shift, unsigned b_shift)
{ {
unsigned i, bits, size, bits_mul; unsigned i, bits, size, bits_mul;
uint8_t info[6]; uint8_t info[6] = {0};
unsigned width = 0; unsigned width = 0;
unsigned height = 0; unsigned height = 0;
const uint8_t *tmp = NULL; const uint8_t *tmp = NULL;

View File

@ -480,7 +480,7 @@ static struct buffer get_char(struct buffer buff, char * c,
static struct buffer parse_string(struct buffer buff, static struct buffer parse_string(struct buffer buff,
struct rmsgpack_dom_value *value, const char **error) struct rmsgpack_dom_value *value, const char **error)
{ {
const char * str_start; const char * str_start = NULL;
char terminator = '\0'; char terminator = '\0';
char c = '\0'; char c = '\0';
int is_binstr = 0; int is_binstr = 0;
@ -649,11 +649,11 @@ clean:
static struct buffer parse_method_call(struct buffer buff, static struct buffer parse_method_call(struct buffer buff,
struct invocation *invocation, const char **error) struct invocation *invocation, const char **error)
{ {
const char *func_name;
size_t func_name_len; size_t func_name_len;
unsigned i; unsigned i;
struct argument args[MAX_ARGS]; struct argument args[MAX_ARGS];
unsigned argi = 0; unsigned argi = 0;
const char *func_name = NULL;
struct registered_func *rf = registered_functions; struct registered_func *rf = registered_functions;
invocation->func = NULL; invocation->func = NULL;
@ -738,9 +738,9 @@ static struct buffer parse_table(struct buffer buff,
struct invocation *invocation, const char **error) struct invocation *invocation, const char **error)
{ {
unsigned i; unsigned i;
const char *ident_name;
size_t ident_len; size_t ident_len;
struct argument args[MAX_ARGS]; struct argument args[MAX_ARGS];
const char *ident_name = NULL;
unsigned argi = 0; unsigned argi = 0;
buff = chomp(buff); buff = chomp(buff);

View File

@ -27,8 +27,8 @@ static struct rmsgpack_dom_value *dom_reader_state_pop(
static void puts_i64(int64_t dec) static void puts_i64(int64_t dec)
{ {
signed char digits[19 + 1]; /* max i64: 9,223,372,036,854,775,807 */
int i; int i;
signed char digits[19 + 1] = {0}; /* max i64: 9,223,372,036,854,775,807 */
uint64_t decimal = (dec < 0) ? (uint64_t)-dec : (uint64_t)+dec; uint64_t decimal = (dec < 0) ? (uint64_t)-dec : (uint64_t)+dec;
digits[19] = '\0'; digits[19] = '\0';
@ -52,10 +52,9 @@ static void puts_i64(int64_t dec)
static void puts_u64(uint64_t decimal) static void puts_u64(uint64_t decimal)
{ {
char digits[20 + 1]; /* max u64: 18,446,744,073,709,551,616 */
int i; int i;
char digits[20 + 1] = {0}; /* max u64: 18,446,744,073,709,551,616 */
digits[20] = '\0';
for (i = sizeof(digits) - 2; i >= 0; i--) for (i = sizeof(digits) - 2; i >= 0; i--)
{ {
digits[i] = decimal % 10; digits[i] = decimal % 10;
@ -446,16 +445,16 @@ int rmsgpack_dom_read(FILE *fp, struct rmsgpack_dom_value *out)
int rmsgpack_dom_read_into(FILE *fp, ...) int rmsgpack_dom_read_into(FILE *fp, ...)
{ {
va_list ap; va_list ap;
struct rmsgpack_dom_value map;
int rv; int rv;
const char *key_name; struct rmsgpack_dom_value map;
struct rmsgpack_dom_value key; struct rmsgpack_dom_value key;
struct rmsgpack_dom_value *value; struct rmsgpack_dom_value *value;
int64_t *int_value; int64_t *int_value;
uint64_t *uint_value; uint64_t *uint_value;
int *bool_value; int *bool_value;
char *buff_value;
uint64_t min_len; uint64_t min_len;
char *buff_value = NULL;
const char *key_name = NULL;
int value_type = 0; int value_type = 0;
va_start(ap, fp); va_start(ap, fp);