Prevent implicit memsets

This commit is contained in:
twinaphex 2016-10-21 05:57:40 +02:00
parent c7658dcf4a
commit c3ab8800f4
10 changed files with 132 additions and 61 deletions

View File

@ -76,7 +76,9 @@ void fill_pathname_expand_special(char *out_path,
)
{
size_t src_size;
char application_dir[PATH_MAX_LENGTH] = {0};
char application_dir[PATH_MAX_LENGTH];
application_dir[0] = '\0';
fill_pathname_application_path(application_dir, sizeof(application_dir));
path_basedir(application_dir);
@ -101,9 +103,11 @@ void fill_pathname_abbreviate_special(char *out_path,
unsigned i;
const char *candidates[3];
const char *notations[3];
char application_dir[PATH_MAX_LENGTH] = {0};
char application_dir[PATH_MAX_LENGTH];
const char *home = getenv("HOME");
application_dir[0] = '\0';
/* application_dir could be zero-string. Safeguard against this.
*
* Keep application dir in front of home, moving app dir to a
@ -238,9 +242,9 @@ void fill_pathname_application_path(char *s, size_t len)
{
pid_t pid;
static const char *exts[] = { "exe", "file", "path/a.out" };
char link_path[PATH_MAX_LENGTH] = {0};
char link_path[PATH_MAX_LENGTH];
*s = '\0';
link_path[0] = *s = '\0';
pid = getpid();
/* Linux, BSD and Solaris paths. Not standardized. */
@ -303,7 +307,9 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_FONT:
#ifdef HAVE_ZARCH
{
char s1[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
s1[0] = '\0';
fill_pathname_application_special(s1, sizeof(s1),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH);
fill_pathname_join(s,
@ -325,8 +331,11 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS:
#ifdef HAVE_XMB
{
char s1[PATH_MAX_LENGTH] = {0};
char s2[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
char s2[PATH_MAX_LENGTH];
s1[0] = s2[0] = '\0';
fill_pathname_application_special(s1, sizeof(s1),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB);
fill_pathname_join(s2, s1, "png",
@ -345,7 +354,10 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
strlcpy(s, settings->path.menu_wallpaper, len);
else
{
char s1[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
s1[0] = '\0';
fill_pathname_application_special(s1, sizeof(s1),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS);
fill_pathname_join(s, s1,
@ -358,10 +370,12 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB:
#ifdef HAVE_XMB
{
char s1[PATH_MAX_LENGTH] = {0};
char s2[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
char s2[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
s1[0] = s2[0] = '\0';
fill_pathname_join(
s1,
settings->directory.assets,
@ -389,7 +403,10 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_ICONS:
#ifdef HAVE_MATERIALUI
{
char s1[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
s1[0] = '\0';
fill_pathname_application_special(s1,
sizeof(s1), APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI);
fill_pathname_slash(s1, sizeof(s1));
@ -400,7 +417,10 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI_FONT:
#ifdef HAVE_MATERIALUI
{
char s1[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
s1[0] = '\0';
fill_pathname_application_special(s1, sizeof(s1),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_MATERIALUI);
fill_pathname_join(s, s1, "Roboto-Regular.ttf", len);
@ -416,7 +436,10 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
strlcpy(s, settings->menu.xmb.font, len);
else
{
char s1[PATH_MAX_LENGTH] = {0};
char s1[PATH_MAX_LENGTH];
s1[0] = '\0';
fill_pathname_application_special(s1, sizeof(s1),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB);
fill_pathname_join(s, s1,

View File

@ -284,7 +284,9 @@ void x11_set_window_attr(Display *dpy, Window win)
static void xdg_screensaver_inhibit(Window wnd)
{
int ret;
char cmd[64] = {0};
char cmd[64];
cmd[0] = '\0';
if (!xdg_screensaver_available)
return;
@ -719,10 +721,12 @@ bool x11_connect(void)
void x11_update_window_title(void *data)
{
char buf[128] = {0};
char buf_fps[128] = {0};
char buf[128];
char buf_fps[128];
settings_t *settings = config_get_ptr();
buf[0] = buf_fps[0] = '\0';
if (video_monitor_get_fps(buf, sizeof(buf), buf_fps, sizeof(buf_fps)))
XStoreName(g_x11_dpy, g_x11_win, buf);
if (settings->fps_show)

View File

@ -446,13 +446,16 @@ static bool gfx_ctx_x_set_video_mode(void *data,
bool fullscreen)
{
XEvent event;
bool true_full = false, windowed_full;
int val, x_off = 0, y_off = 0;
XVisualInfo *vi = NULL;
XSetWindowAttributes swa = {0};
bool true_full = false;
bool windowed_full = false;
int val = 0;
int x_off = 0;
int y_off = 0;
XVisualInfo *vi = NULL;
XSetWindowAttributes swa = {0};
int (*old_handler)(Display*, XErrorEvent*) = NULL;
settings_t *settings = config_get_ptr();
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
settings_t *settings = config_get_ptr();
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
frontend_driver_install_signal_handler();

View File

@ -35,13 +35,15 @@ using namespace std;
static bool read_shader_file(const char *path, vector<string> *output, bool root_file)
{
vector<const char *> lines;
char include_path[PATH_MAX_LENGTH];
char tmp[PATH_MAX_LENGTH];
char *ptr = NULL;
char *buf = nullptr;
ssize_t len = 0;
char include_path[PATH_MAX_LENGTH] = {0};
char tmp[PATH_MAX_LENGTH] = {0};
const char *basename = path_basename(path);
include_path[0] = tmp[0] = '\0';
if (!filestream_read_file(path, (void**)&buf, &len))
{
RARCH_ERR("Failed to open shader file: \"%s\".\n", path);

View File

@ -848,7 +848,9 @@ static void gl_cg_set_pass_attrib(
struct cg_fbo_params *fbo,
const char *attr)
{
char attr_buf[64] = {0};
char attr_buf[64];
attr_buf[0] = '\0';
snprintf(attr_buf, sizeof(attr_buf), "%s.texture", attr);
if (!fbo->tex)
@ -920,7 +922,9 @@ static void gl_cg_set_program_attributes(void *data, unsigned i)
if (i > 1)
{
char pass_str[64] = {0};
char pass_str[64];
pass_str[0] = '\0';
snprintf(pass_str, sizeof(pass_str), "PASSPREV%u", i);
gl_cg_set_pass_attrib(&cg->prg[i], &cg->prg[i].orig, pass_str);
@ -928,10 +932,10 @@ static void gl_cg_set_program_attributes(void *data, unsigned i)
for (j = 0; j < PREV_TEXTURES; j++)
{
char attr_buf_tex[64] = {0};
char attr_buf_vid_size[64] = {0};
char attr_buf_tex_size[64] = {0};
char attr_buf_coord[64] = {0};
char attr_buf_tex[64];
char attr_buf_vid_size[64];
char attr_buf_tex_size[64];
char attr_buf_coord[64];
static const char *prev_names[PREV_TEXTURES] = {
"PREV",
"PREV1",
@ -942,6 +946,9 @@ static void gl_cg_set_program_attributes(void *data, unsigned i)
"PREV6",
};
attr_buf_tex[0] = attr_buf_vid_size[0] = attr_buf_tex_size[0] =
attr_buf_coord[0] = '\0';
snprintf(attr_buf_tex, sizeof(attr_buf_tex),
"%s.texture", prev_names[j]);
snprintf(attr_buf_vid_size, sizeof(attr_buf_vid_size),
@ -970,7 +977,9 @@ static void gl_cg_set_program_attributes(void *data, unsigned i)
for (j = 0; j + 1 < i; j++)
{
char pass_str[64] = {0};
char pass_str[64];
pass_str[0] = '\0';
snprintf(pass_str, sizeof(pass_str), "PASS%u", j + 1);
gl_cg_set_pass_attrib(&cg->prg[i], &cg->prg[i].fbo[j], pass_str);

View File

@ -158,7 +158,9 @@ static GLint gl_glsl_get_uniform(glsl_shader_data_t *glsl,
{
unsigned i;
GLint loc;
char buf[64] = {0};
char buf[64];
buf[0] = '\0';
snprintf(buf, sizeof(buf), "%s%s", glsl->shader->prefix, base);
loc = glGetUniformLocation(prog, buf);
@ -181,7 +183,9 @@ static GLint gl_glsl_get_attrib(glsl_shader_data_t *glsl,
{
unsigned i;
GLint loc;
char buf[64] = {0};
char buf[64];
buf[0] = '\0';
snprintf(buf, sizeof(buf), "%s%s", glsl->shader->prefix, base);
loc = glGetUniformLocation(prog, buf);
@ -249,7 +253,9 @@ static bool gl_glsl_compile_shader(glsl_shader_data_t *glsl,
{
GLint status;
const char *source[4];
char version[32] = {0};
char version[32];
version[0] = '\0';
if (glsl_core && !strstr(program, "#version"))
{
@ -544,10 +550,12 @@ static void gl_glsl_find_uniforms_frame(glsl_shader_data_t *glsl,
GLuint prog,
struct shader_uniforms_frame *frame, const char *base)
{
char texture[64] = {0};
char texture_size[64] = {0};
char input_size[64] = {0};
char tex_coord[64] = {0};
char texture[64];
char texture_size[64];
char input_size[64];
char tex_coord[64];
texture[0] = texture_size[0] = input_size[0] = tex_coord[0] = '\0';
snprintf(texture, sizeof(texture), "%s%s", base, "Texture");
snprintf(texture_size, sizeof(texture_size), "%s%s", base, "TextureSize");
@ -569,7 +577,9 @@ static void gl_glsl_find_uniforms(glsl_shader_data_t *glsl,
struct shader_uniforms *uni)
{
unsigned i;
char frame_base[64] = {0};
char frame_base[64];
frame_base[0] = '\0';
glUseProgram(prog);
@ -828,7 +838,9 @@ static void *gl_glsl_init(void *data, const char *path)
{
if (*glsl->shader->pass[i].alias)
{
char define[128] = {0};
char define[128];
define[0] = '\0';
snprintf(define, sizeof(define), "#define %s_ALIAS\n",
glsl->shader->pass[i].alias);

View File

@ -55,14 +55,16 @@
struct string_list *dir_list_new_special(const char *input_dir,
enum dir_list_type type, const char *filter)
{
char ext_shaders[PATH_MAX_LENGTH] = {0};
char ext_name[PATH_MAX_LENGTH] = {0};
char ext_shaders[PATH_MAX_LENGTH];
char ext_name[PATH_MAX_LENGTH];
const char *dir = NULL;
const char *exts = NULL;
bool include_dirs = false;
bool recursive = false;
settings_t *settings = config_get_ptr();
ext_shaders[0] = ext_name[0] = '\0';
(void)input_dir;
switch (type)

View File

@ -125,11 +125,13 @@ bool cheat_manager_save(const char *path)
{
bool ret;
unsigned i;
char buf[PATH_MAX_LENGTH];
char cheats_file[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
char buf[PATH_MAX_LENGTH] = {0};
char cheats_file[PATH_MAX_LENGTH] = {0};
settings_t *settings = config_get_ptr();
cheat_manager_t *handle = cheat_manager_state;
cheat_manager_t *handle = cheat_manager_state;
buf[0] = cheats_file[0] = '\0';
fill_pathname_join(buf, settings->path.cheat_database,
path, sizeof(buf));
@ -154,10 +156,12 @@ bool cheat_manager_save(const char *path)
for (i = 0; i < handle->size; i++)
{
char key[64] = {0};
char desc_key[256] = {0};
char code_key[256] = {0};
char enable_key[256] = {0};
char key[64];
char desc_key[256];
char code_key[256];
char enable_key[256];
key[0] = desc_key[0] = code_key[0] = enable_key[0] = '\0';
snprintf(key, sizeof(key), "cheat%u", i);
snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i);
@ -231,13 +235,15 @@ bool cheat_manager_load(const char *path)
for (i = 0; i < cheats; i++)
{
char key[64] = {0};
char desc_key[256] = {0};
char code_key[256] = {0};
char enable_key[256] = {0};
char key[64];
char desc_key[256];
char code_key[256];
char enable_key[256];
char *tmp = NULL;
bool tmp_bool = false;
key[0] = desc_key[0] = code_key[0] = enable_key[0] = '\0';
snprintf(key, sizeof(key), "cheat%u", i);
snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i);
snprintf(code_key, sizeof(code_key), "cheat%u_code", i);

View File

@ -228,7 +228,9 @@ static void retroarch_print_features(void)
static void retroarch_print_version(void)
{
char str[PATH_MAX_LENGTH] = {0};
char str[PATH_MAX_LENGTH];
str[0] = '\0';
fprintf(stderr, "%s: %s -- v%s",
msg_hash_to_str(MSG_PROGRAM),
@ -895,8 +897,8 @@ static bool retroarch_init_state(void)
bool retroarch_validate_game_options(char *s, size_t len, bool mkdir)
{
char core_path[PATH_MAX_LENGTH] = {0};
char config_directory[PATH_MAX_LENGTH] = {0};
char core_path[PATH_MAX_LENGTH];
char config_directory[PATH_MAX_LENGTH];
const char *core_name = NULL;
const char *game_name = NULL;
rarch_system_info_t *system = NULL;
@ -911,6 +913,8 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir)
if (string_is_empty(core_name) || string_is_empty(game_name))
return false;
config_directory[0] = core_path[0] = '\0';
fill_pathname_application_special(config_directory, sizeof(config_directory),
APPLICATION_SPECIAL_DIRECTORY_CONFIG);
@ -1022,7 +1026,9 @@ bool retroarch_main_init(int argc, char *argv[])
if (verbosity_is_enabled())
{
char str[PATH_MAX_LENGTH] = {0};
char str[PATH_MAX_LENGTH];
str[0] = '\0';
RARCH_LOG_OUTPUT("=== Build =======================================\n");
retroarch_get_capabilities(RARCH_CAPABILITIES_CPU, str, sizeof(str));

View File

@ -1327,9 +1327,11 @@ static bool dump_to_file_desperate(const void *data,
size_t size, unsigned type)
{
time_t time_;
char timebuf[256] = {0};
char application_data[PATH_MAX_LENGTH] = {0};
char path[PATH_MAX_LENGTH] = {0};
char timebuf[256];
char application_data[PATH_MAX_LENGTH];
char path[PATH_MAX_LENGTH];
timebuf[0] = application_data[0] = path[0] = '\0';
if (!fill_pathname_application_data(application_data,
sizeof(application_data)))
@ -1425,9 +1427,11 @@ bool event_load_save_files(void)
void path_init_savefile_rtc(void)
{
union string_list_elem_attr attr;
char savefile_name_rtc[PATH_MAX_LENGTH] = {0};
char savefile_name_rtc[PATH_MAX_LENGTH];
global_t *global = global_get_ptr();
savefile_name_rtc[0] = '\0';
attr.i = RETRO_MEMORY_SAVE_RAM;
string_list_append(task_save_files, global->name.savefile, attr);