mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 15:40:44 +00:00
(libretro-common) Cleanups
This commit is contained in:
parent
b31723236d
commit
cdec12faa5
@ -52,9 +52,9 @@ static char *getaline(FILE *file)
|
||||
{
|
||||
char* newline = (char*)malloc(9);
|
||||
char* newline_tmp = NULL;
|
||||
size_t cur_size = 8;
|
||||
size_t idx = 0;
|
||||
int in = getc(file);
|
||||
size_t cur_size = 8;
|
||||
size_t idx = 0;
|
||||
int in = getc(file);
|
||||
|
||||
if (!newline)
|
||||
return NULL;
|
||||
@ -84,7 +84,8 @@ static char *getaline(FILE *file)
|
||||
|
||||
static char *extract_value(char *line, bool is_value)
|
||||
{
|
||||
char *save = NULL, *tok = NULL;
|
||||
char *save = NULL;
|
||||
char *tok = NULL;
|
||||
|
||||
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)
|
||||
{
|
||||
char real_path[PATH_MAX_LENGTH];
|
||||
config_file_t *sub_conf = NULL;
|
||||
char *path = extract_value(line, false);
|
||||
char real_path[PATH_MAX_LENGTH] = {0};
|
||||
config_file_t *sub_conf = NULL;
|
||||
char *path = extract_value(line, false);
|
||||
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
@ -268,11 +270,11 @@ static char *strip_comment(char *str)
|
||||
static bool parse_line(config_file_t *conf,
|
||||
struct config_entry_list *list, char *line)
|
||||
{
|
||||
char* comment = NULL;
|
||||
char* key = (char*)malloc(9);
|
||||
char* key_tmp = NULL;
|
||||
char *comment = NULL;
|
||||
char *key = (char*)malloc(9);
|
||||
char *key_tmp = NULL;
|
||||
size_t cur_size = 8;
|
||||
size_t idx = 0;
|
||||
size_t idx = 0;
|
||||
|
||||
if (!key)
|
||||
return false;
|
||||
@ -780,7 +782,7 @@ void config_set_path(config_file_t *conf, const char *entry, const char *val)
|
||||
#if defined(RARCH_CONSOLE)
|
||||
config_set_string(conf, entry, val);
|
||||
#else
|
||||
char buf[PATH_MAX_LENGTH];
|
||||
char buf[PATH_MAX_LENGTH] = {0};
|
||||
fill_pathname_abbreviate_special(buf, val, sizeof(buf));
|
||||
config_set_string(conf, entry, buf);
|
||||
#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)
|
||||
{
|
||||
char buf[128];
|
||||
char buf[128] = {0};
|
||||
#ifdef __cplusplus
|
||||
snprintf(buf, sizeof(buf), "%f", (float)val);
|
||||
#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)
|
||||
{
|
||||
char buf[128];
|
||||
char buf[128] = {0};
|
||||
snprintf(buf, sizeof(buf), "%f", val);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
||||
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);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
||||
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);
|
||||
config_set_string(conf, key, buf);
|
||||
}
|
||||
|
||||
void config_set_uint64(config_file_t *conf, const char *key, uint64_t val)
|
||||
{
|
||||
char buf[128];
|
||||
char buf[128] = {0};
|
||||
#ifdef _WIN32
|
||||
snprintf(buf, sizeof(buf), "%I64u", val);
|
||||
#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)
|
||||
{
|
||||
char buf[2];
|
||||
char buf[2] = {0};
|
||||
snprintf(buf, sizeof(buf), "%c", val);
|
||||
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)
|
||||
{
|
||||
const struct config_entry_list *head = conf->entries;
|
||||
|
||||
if (!head)
|
||||
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)
|
||||
{
|
||||
const struct config_entry_list *next = entry->next;
|
||||
|
||||
if (!next)
|
||||
return false;
|
||||
|
||||
|
@ -204,8 +204,6 @@ static int parse_dir_entry(const char *name, char *file_path,
|
||||
struct string_list *dir_list_new(const char *dir,
|
||||
const char *ext, bool include_dirs)
|
||||
{
|
||||
char path_buf[PATH_MAX_LENGTH];
|
||||
struct string_list *ext_list, *list;
|
||||
#ifdef _WIN32
|
||||
WIN32_FIND_DATA ffd;
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
@ -213,8 +211,10 @@ struct string_list *dir_list_new(const char *dir,
|
||||
DIR *directory = NULL;
|
||||
const struct dirent *entry = NULL;
|
||||
#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;
|
||||
|
||||
if (!(list = string_list_new()))
|
||||
@ -232,11 +232,11 @@ struct string_list *dir_list_new(const char *dir,
|
||||
|
||||
do
|
||||
{
|
||||
int ret = 0;
|
||||
char file_path[PATH_MAX_LENGTH];
|
||||
const char *name = ffd.cFileName;
|
||||
const char *file_ext = path_get_extension(name);
|
||||
bool is_dir = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||
int ret = 0;
|
||||
char file_path[PATH_MAX_LENGTH] = {0};
|
||||
const char *name = ffd.cFileName;
|
||||
const char *file_ext = path_get_extension(name);
|
||||
bool is_dir = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
fill_pathname_join(file_path, dir, name, sizeof(file_path));
|
||||
|
||||
@ -264,11 +264,11 @@ error:
|
||||
|
||||
while ((entry = readdir(directory)))
|
||||
{
|
||||
int ret = 0;
|
||||
char file_path[PATH_MAX_LENGTH];
|
||||
const char *name = entry->d_name;
|
||||
const char *file_ext = path_get_extension(name);
|
||||
bool is_dir = false;
|
||||
int ret = 0;
|
||||
char file_path[PATH_MAX_LENGTH] = {0};
|
||||
const char *name = entry->d_name;
|
||||
const char *file_ext = path_get_extension(name);
|
||||
bool is_dir = false;
|
||||
|
||||
fill_pathname_join(file_path, dir, name, sizeof(file_path));
|
||||
|
||||
|
@ -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))
|
||||
{
|
||||
char new_path[PATH_MAX_LENGTH];
|
||||
char new_path[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
if (data->extraction_directory)
|
||||
fill_pathname_join(new_path, data->extraction_directory,
|
||||
|
@ -212,8 +212,8 @@ bool path_file_exists(const char *path)
|
||||
void fill_pathname(char *out_path, const char *in_path,
|
||||
const char *replace, size_t size)
|
||||
{
|
||||
char tmp_path[PATH_MAX_LENGTH];
|
||||
char *tok;
|
||||
char tmp_path[PATH_MAX_LENGTH] = {0};
|
||||
char *tok = NULL;
|
||||
|
||||
rarch_assert(strlcpy(tmp_path, in_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 *base = NULL;
|
||||
|
||||
fill_pathname_slash(in_dir, size);
|
||||
base = path_basename(in_basename);
|
||||
rarch_assert(strlcat(in_dir, base, size) < size);
|
||||
@ -318,7 +319,10 @@ void fill_pathname_dir(char *in_dir, const char *in_basename,
|
||||
**/
|
||||
void fill_pathname_base(char *out, const char *in_path, size_t size)
|
||||
{
|
||||
const char *ptr = find_last_slash(in_path);
|
||||
const char *ptr_bak = NULL;
|
||||
const char *ptr = find_last_slash(in_path);
|
||||
|
||||
(void)ptr_bak;
|
||||
|
||||
if (ptr)
|
||||
ptr++;
|
||||
@ -332,9 +336,8 @@ void fill_pathname_base(char *out, const char *in_path, size_t size)
|
||||
* /path/to/archive.7z#folder/mygame.img
|
||||
* basename would be mygame.img in both cases
|
||||
*/
|
||||
|
||||
const char *ptr_bak = ptr;
|
||||
ptr = strchr(ptr_bak,'#');
|
||||
ptr_bak = ptr;
|
||||
ptr = strchr(ptr_bak,'#');
|
||||
if (ptr)
|
||||
ptr++;
|
||||
else
|
||||
@ -453,11 +456,15 @@ void path_parent_dir(char *path)
|
||||
**/
|
||||
const char *path_basename(const char *path)
|
||||
{
|
||||
const char *last_hash = NULL;
|
||||
const char *last = find_last_slash(path);
|
||||
|
||||
(void)last_hash;
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* 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)
|
||||
return last_hash + 1;
|
||||
#endif
|
||||
@ -497,7 +504,8 @@ bool path_is_absolute(const char *path)
|
||||
void path_resolve_realpath(char *buf, size_t size)
|
||||
{
|
||||
#ifndef RARCH_CONSOLE
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
char tmp[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
strlcpy(tmp, buf, sizeof(tmp));
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -558,8 +566,8 @@ bool path_mkdir(const char *dir)
|
||||
{
|
||||
const char *target = NULL;
|
||||
/* Use heap. Real chance of stack overflow if we recurse too hard. */
|
||||
char *basedir = strdup(dir);
|
||||
bool ret = true;
|
||||
char *basedir = strdup(dir);
|
||||
bool ret = true;
|
||||
|
||||
if (!basedir)
|
||||
return false;
|
||||
@ -682,7 +690,9 @@ void fill_pathname_join_delim(char *out_path, const char *dir,
|
||||
void fill_short_pathname_representation(char* out_rep,
|
||||
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), "",
|
||||
sizeof(path_short));
|
||||
|
||||
|
@ -221,10 +221,10 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||
{
|
||||
long pos, file_len;
|
||||
FILE *file;
|
||||
char header[8];
|
||||
char header[8] = {0};
|
||||
struct rpng_t rpng = {{0}};
|
||||
bool ret = true;
|
||||
int retval = 0;
|
||||
bool ret = true;
|
||||
int retval = 0;
|
||||
|
||||
*data = NULL;
|
||||
*width = 0;
|
||||
|
@ -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)
|
||||
{
|
||||
unsigned i;
|
||||
char header[8];
|
||||
char header[8] = {0};
|
||||
|
||||
if (!rpng)
|
||||
return false;
|
||||
|
@ -27,10 +27,10 @@ bool rtga_image_load_shift(uint8_t *buf,
|
||||
unsigned g_shift, unsigned b_shift)
|
||||
{
|
||||
unsigned i, bits, size, bits_mul;
|
||||
uint8_t info[6];
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
const uint8_t *tmp = NULL;
|
||||
uint8_t info[6] = {0};
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
const uint8_t *tmp = NULL;
|
||||
struct texture_image *out_img = (struct texture_image*)data;
|
||||
|
||||
if (buf[2] != 2)
|
||||
|
@ -480,10 +480,10 @@ static struct buffer get_char(struct buffer buff, char * c,
|
||||
static struct buffer parse_string(struct buffer buff,
|
||||
struct rmsgpack_dom_value *value, const char **error)
|
||||
{
|
||||
const char * str_start;
|
||||
char terminator = '\0';
|
||||
char c = '\0';
|
||||
int is_binstr = 0;
|
||||
const char * str_start = NULL;
|
||||
char terminator = '\0';
|
||||
char c = '\0';
|
||||
int is_binstr = 0;
|
||||
|
||||
(void)c;
|
||||
|
||||
@ -649,11 +649,11 @@ clean:
|
||||
static struct buffer parse_method_call(struct buffer buff,
|
||||
struct invocation *invocation, const char **error)
|
||||
{
|
||||
const char *func_name;
|
||||
size_t func_name_len;
|
||||
unsigned i;
|
||||
struct argument args[MAX_ARGS];
|
||||
unsigned argi = 0;
|
||||
const char *func_name = NULL;
|
||||
struct registered_func *rf = registered_functions;
|
||||
|
||||
invocation->func = NULL;
|
||||
@ -738,9 +738,9 @@ static struct buffer parse_table(struct buffer buff,
|
||||
struct invocation *invocation, const char **error)
|
||||
{
|
||||
unsigned i;
|
||||
const char *ident_name;
|
||||
size_t ident_len;
|
||||
struct argument args[MAX_ARGS];
|
||||
const char *ident_name = NULL;
|
||||
unsigned argi = 0;
|
||||
|
||||
buff = chomp(buff);
|
||||
|
@ -27,9 +27,9 @@ static struct rmsgpack_dom_value *dom_reader_state_pop(
|
||||
|
||||
static void puts_i64(int64_t dec)
|
||||
{
|
||||
signed char digits[19 + 1]; /* max i64: 9,223,372,036,854,775,807 */
|
||||
int i;
|
||||
uint64_t decimal = (dec < 0) ? (uint64_t)-dec : (uint64_t)+dec;
|
||||
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;
|
||||
|
||||
digits[19] = '\0';
|
||||
|
||||
@ -52,10 +52,9 @@ static void puts_i64(int64_t dec)
|
||||
|
||||
static void puts_u64(uint64_t decimal)
|
||||
{
|
||||
char digits[20 + 1]; /* max u64: 18,446,744,073,709,551,616 */
|
||||
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--)
|
||||
{
|
||||
digits[i] = decimal % 10;
|
||||
@ -446,17 +445,17 @@ int rmsgpack_dom_read(FILE *fp, struct rmsgpack_dom_value *out)
|
||||
int rmsgpack_dom_read_into(FILE *fp, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct rmsgpack_dom_value map;
|
||||
int rv;
|
||||
const char *key_name;
|
||||
struct rmsgpack_dom_value map;
|
||||
struct rmsgpack_dom_value key;
|
||||
struct rmsgpack_dom_value *value;
|
||||
int64_t *int_value;
|
||||
uint64_t *uint_value;
|
||||
int *bool_value;
|
||||
char *buff_value;
|
||||
uint64_t min_len;
|
||||
int value_type = 0;
|
||||
char *buff_value = NULL;
|
||||
const char *key_name = NULL;
|
||||
int value_type = 0;
|
||||
|
||||
va_start(ap, fp);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user