Prevent implicit memsets

This commit is contained in:
twinaphex 2016-10-09 09:56:03 +02:00
parent 78a09be030
commit 481ebced22
17 changed files with 598 additions and 581 deletions

View File

@ -23,6 +23,7 @@
#if __TEST_FNMATCH__
#include <assert.h>
#endif
#include <stddef.h>
#include <compat/fnmatch.h>
@ -34,9 +35,10 @@
int rl_fnmatch(const char *pattern, const char *string, int flags)
{
const char *c;
int charmatch = 0;
int rv;
const char *c = NULL;
int charmatch = 0;
for (c = pattern; *c != '\0'; c++)
{
/* String ended before pattern */

File diff suppressed because it is too large Load Diff

View File

@ -43,10 +43,10 @@ static int casencmp(const char *a, const char *b, size_t n)
char *strcasestr_retro__(const char *haystack, const char *needle)
{
size_t i, hay_len, needle_len, search_off;
size_t i, search_off;
size_t hay_len = strlen(haystack);
size_t needle_len = strlen(needle);
hay_len = strlen(haystack);
needle_len = strlen(needle);
if (needle_len > hay_len)
return NULL;

View File

@ -34,7 +34,7 @@
size_t strlcpy(char *dest, const char *source, size_t size)
{
size_t src_size = 0;
size_t n = size;
size_t n = size;
if (n)
while (--n && (*dest++ = *source++)) src_size++;

View File

@ -520,7 +520,7 @@ uint64_t cpu_features_get(void)
{
int flags[4];
int vendor_shuffle[3];
char vendor[13] = {0};
char vendor[13];
size_t len = 0;
uint64_t cpu_flags = 0;
uint64_t cpu = 0;
@ -606,6 +606,8 @@ uint64_t cpu_features_get(void)
vendor_shuffle[0] = flags[1];
vendor_shuffle[1] = flags[3];
vendor_shuffle[2] = flags[2];
vendor[0] = '\0';
memcpy(vendor, vendor_shuffle, sizeof(vendor_shuffle));
/* printf("[CPUID]: Vendor: %s\n", vendor); */

View File

@ -139,7 +139,7 @@ static int sevenzip_file_read(
for (i = 0; i < db.db.NumFiles; i++)
{
size_t len;
char infile[PATH_MAX_LENGTH] = {0};
char infile[PATH_MAX_LENGTH];
size_t offset = 0;
size_t outSizeProcessed = 0;
const CSzFileItem *f = db.db.Files + i;
@ -166,7 +166,9 @@ static int sevenzip_file_read(
}
SzArEx_GetFileNameUtf16(&db, i, temp);
res = SZ_ERROR_FAIL;
res = SZ_ERROR_FAIL;
infile[0] = '\0';
if (temp)
res = utf16_to_char_string(temp, infile, sizeof(infile))
? SZ_OK : SZ_ERROR_FAIL;
@ -340,13 +342,15 @@ static int sevenzip_parse_file_iterate_step_internal(
if (len < PATH_MAX_LENGTH && !file->IsDir)
{
char infile[PATH_MAX_LENGTH];
SRes res = SZ_ERROR_FAIL;
char infile[PATH_MAX_LENGTH] = {0};
uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t));
if (!temp)
return -1;
infile[0] = '\0';
SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index,
temp);
@ -375,8 +379,10 @@ static int sevenzip_parse_file_iterate_step_internal(
}
static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
const char *valid_exts, struct archive_extract_userdata *userdata, file_archive_file_cb file_cb)
const char *valid_exts,
struct archive_extract_userdata *userdata, file_archive_file_cb file_cb)
{
char filename[PATH_MAX_LENGTH];
const uint8_t *cdata = NULL;
uint32_t checksum = 0;
uint32_t size = 0;
@ -384,7 +390,6 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
unsigned cmode = 0;
unsigned payload = 0;
struct sevenzip_context_t *sevenzip_context = NULL;
char filename[PATH_MAX_LENGTH] = {0};
int ret = sevenzip_parse_file_iterate_step_internal(state, filename,
&cdata, &cmode, &size, &csize,
&checksum, &payload, userdata);
@ -392,8 +397,9 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
if (ret != 1)
return ret;
filename[0] = '\0';
userdata->extracted_file_path = filename;
userdata->crc = checksum;
userdata->crc = checksum;
if (file_cb && !file_cb(filename, valid_exts, cdata, cmode,
csize, size, checksum, userdata))

View File

@ -258,7 +258,7 @@ static void add_child_list(config_file_t *parent, config_file_t *child)
static void add_sub_conf(config_file_t *conf, char *line)
{
char real_path[PATH_MAX_LENGTH] = {0};
char real_path[PATH_MAX_LENGTH];
config_file_t *sub_conf = NULL;
char *path = extract_value(line, false);
@ -267,6 +267,8 @@ static void add_sub_conf(config_file_t *conf, char *line)
add_include_list(conf, path);
real_path[0] = '\0';
#ifdef _WIN32
fill_pathname_resolve_relative(real_path, conf->path,
path, sizeof(real_path));
@ -802,7 +804,9 @@ 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] = {0};
char buf[PATH_MAX_LENGTH];
buf[0] = '\0';
fill_pathname_abbreviate_special(buf, val, sizeof(buf));
config_set_string(conf, entry, buf);
#endif
@ -810,7 +814,9 @@ 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] = {0};
char buf[128];
buf[0] = '\0';
#ifdef __cplusplus
snprintf(buf, sizeof(buf), "%f", (float)val);
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
@ -823,28 +829,36 @@ 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] = {0};
char buf[128];
buf[0] = '\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] = {0};
char buf[128];
buf[0] = '\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] = {0};
char buf[128];
buf[0] = '\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] = {0};
char buf[128];
buf[0] = '\0';
#ifdef _WIN32
snprintf(buf, sizeof(buf), "%I64u", val);
#else
@ -855,7 +869,9 @@ 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] = {0};
char buf[2];
buf[0] = '\0';
snprintf(buf, sizeof(buf), "%c", val);
config_set_string(conf, key, buf);
}

View File

@ -467,9 +467,11 @@ void fill_dated_filename(char *out_filename,
void fill_str_dated_filename(char *out_filename,
const char *in_str, const char *ext, size_t size)
{
char format[256] = {0};
char format[256];
time_t cur_time = time(NULL);
format[0] = '\0';
strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", localtime(&cur_time));
strlcpy(out_filename, in_str, size);
strlcat(out_filename, format, size);

View File

@ -508,14 +508,16 @@ static void SHA1Input(SHA1Context *context,
int sha1_calculate(const char *path, char *result)
{
unsigned char buff[4096] = {0};
SHA1Context sha;
int rv = 1;
unsigned char buff[4096];
int rv = 1;
RFILE *fd = filestream_open(path, RFILE_MODE_READ, -1);
if (!fd)
goto error;
buff[0] = '\0';
SHA1Reset(&sha);
do

View File

@ -437,15 +437,16 @@ void file_list_get_last(const file_list_t *list,
bool file_list_search(const file_list_t *list, const char *needle, size_t *idx)
{
size_t i;
const char *alt;
bool ret = false;
const char *alt = NULL;
bool ret = false;
if (!list)
return false;
for (i = 0; i < list->size; i++)
{
const char *str;
const char *str = NULL;
file_list_get_alt_at_offset(list, i, &alt);
if (!alt)
{

View File

@ -290,11 +290,13 @@ bool string_list_find_elem_prefix(const struct string_list *list,
const char *prefix, const char *elem)
{
size_t i;
char prefixed[PATH_MAX_LENGTH] = {0};
char prefixed[PATH_MAX_LENGTH];
if (!list)
return false;
prefixed[0] = '\0';
strlcpy(prefixed, prefix, sizeof(prefixed));
strlcat(prefixed, elem, sizeof(prefixed));

View File

@ -254,7 +254,9 @@ struct http_t *net_http_new(struct http_connection_t *conn)
if (conn->port != 80)
{
char portstr[16] = {0};
char portstr[16];
portstr[0] = '\0';
snprintf(portstr, sizeof(portstr), ":%i", conn->port);
net_http_send_str(fd, &error, portstr);

View File

@ -62,6 +62,8 @@ static void task_queue_msg_push(unsigned prio, unsigned duration,
char buf[1024];
va_list ap;
buf[0] = '\0';
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);

View File

@ -79,9 +79,10 @@ char *string_replace_substring(const char *in,
const char *pattern, const char *replacement)
{
size_t numhits, pattern_len, replacement_len, outlen;
const char *inat;
const char *inprev;
char *out, *outat;
const char *inat = NULL;
const char *inprev = NULL;
char *out = NULL;
char *outat = NULL;
/* if either pattern or replacement is NULL,
* duplicate in and let caller handle it. */

View File

@ -356,8 +356,8 @@ static bool load_content_from_compressed_archive(
bool need_fullpath, const char *path)
{
union string_list_elem_attr attributes;
char new_path[PATH_MAX_LENGTH] = {0};
char new_basedir[PATH_MAX_LENGTH] = {0};
char new_path[PATH_MAX_LENGTH];
char new_basedir[PATH_MAX_LENGTH];
ssize_t new_path_len = 0;
bool ret = false;
rarch_system_info_t *sys_info= NULL;
@ -386,7 +386,10 @@ static bool load_content_from_compressed_archive(
sizeof(new_basedir));
}
attributes.i = 0;
new_path[0] = '\0';
new_basedir[0] = '\0';
attributes.i = 0;
fill_pathname_join(new_path, new_basedir,
path_basename(path), sizeof(new_path));
@ -425,8 +428,8 @@ static bool init_content_file_extract(
for (i = 0; i < content->size; i++)
{
char temp_content[PATH_MAX_LENGTH] = {0};
char new_path[PATH_MAX_LENGTH] = {0};
char temp_content[PATH_MAX_LENGTH];
char new_path[PATH_MAX_LENGTH];
bool contains_compressed = NULL;
bool block_extract = content->elems[i].attr.i & 1;
const char *valid_ext = system->info.valid_extensions;
@ -447,6 +450,8 @@ static bool init_content_file_extract(
continue;
}
temp_content[0] = new_path[0] = '\0';
strlcpy(temp_content, content->elems[i].data,
sizeof(temp_content));
@ -867,8 +872,10 @@ static bool task_load_content(content_ctx_info_t *content_info,
bool launched_from_menu,
enum content_mode_load mode)
{
char name[PATH_MAX_LENGTH] = {0};
char msg[PATH_MAX_LENGTH] = {0};
char name[PATH_MAX_LENGTH];
char msg[PATH_MAX_LENGTH];
name[0] = msg[0] = '\0';
if (launched_from_menu)
{
@ -897,10 +904,12 @@ static bool task_load_content(content_ctx_info_t *content_info,
/* Push entry to top of history playlist */
if (content_is_inited() || content_does_not_need_content())
{
char tmp[PATH_MAX_LENGTH] = {0};
char tmp[PATH_MAX_LENGTH];
struct retro_system_info *info = NULL;
rarch_system_info_t *system = NULL;
tmp[0] = '\0';
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
if (system)
info = &system->info;

View File

@ -51,7 +51,9 @@ typedef struct db_handle
static int task_database_iterate_start(database_info_handle_t *db,
const char *name)
{
char msg[128] = {0};
char msg[128];
msg[0] = '\0';
snprintf(msg, sizeof(msg),
STRING_REP_ULONG "/" STRING_REP_ULONG ": %s %s...\n",
@ -107,9 +109,13 @@ static int iso_get_serial(database_state_handle_t *db_state,
static int cue_get_serial(database_state_handle_t *db_state,
database_info_handle_t *db, const char *name, char* serial)
{
char track_path[PATH_MAX_LENGTH];
int32_t offset = 0;
char track_path[PATH_MAX_LENGTH] = {0};
int rv = find_first_data_track(name,
int rv = 0;
track_path[0] = '\0';
rv = find_first_data_track(name,
&offset, track_path, PATH_MAX_LENGTH);
if (rv < 0)
@ -329,7 +335,9 @@ static int task_database_iterate_crc_lookup(
if (db_state->entry_index == 0)
{
char query[50] = {0};
char query[50];
query[0] = '\0';
if (!core_info_database_supports_content_path(db_state->list->elems[db_state->list_index].data, name) &&
!core_info_unsupported_content_path(name))
@ -450,13 +458,15 @@ static int task_database_iterate_serial_lookup(
if (db_state->entry_index == 0)
{
char query[50] = {0};
char query[50];
char *serial_buf =
bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
if (!serial_buf)
return 1;
query[0] = '\0';
snprintf(query, sizeof(query), "{'serial': b'%s'}", serial_buf);
database_info_list_iterate_new(db_state, query);

View File

@ -382,7 +382,7 @@ int find_first_data_track(const char *cue_path,
int32_t *offset, char *track_path, size_t max_len)
{
int rv;
char tmp_token[MAX_TOKEN_LEN] = {0};
char tmp_token[MAX_TOKEN_LEN];
RFILE *fd =
filestream_open(cue_path, RFILE_MODE_READ, -1);
@ -395,6 +395,8 @@ int find_first_data_track(const char *cue_path,
RARCH_LOG("Parsing CUE file '%s'...\n", cue_path);
tmp_token[0] = '\0';
while (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
{
if (string_is_equal(tmp_token, "FILE"))