mirror of
https://github.com/libretro/RetroArch.git
synced 2025-01-31 22:14:06 +00:00
More strings being moved from heap to stack
This commit is contained in:
parent
a5f3ff9c18
commit
624a70f062
@ -576,8 +576,8 @@ int retro_vfs_file_remove_impl(const char *path)
|
||||
/* TODO: this may not work if trying to move a directory */
|
||||
int retro_vfs_file_rename_impl(const char *old_path, const char *new_path)
|
||||
{
|
||||
char *new_file_name;
|
||||
char *new_dir_path;
|
||||
char new_file_name[PATH_MAX_LENGTH];
|
||||
char new_dir_path[PATH_MAX_LENGTH];
|
||||
wchar_t *new_file_name_wide;
|
||||
wchar_t *old_path_wide, *new_dir_path_wide;
|
||||
Platform::String^ old_path_str;
|
||||
@ -587,24 +587,23 @@ int retro_vfs_file_rename_impl(const char *old_path, const char *new_path)
|
||||
if (!old_path || !*old_path || !new_path || !*new_path)
|
||||
return -1;
|
||||
|
||||
new_file_name[0] = '\0';
|
||||
new_dir_path [0] = '\0';
|
||||
|
||||
old_path_wide = utf8_to_utf16_string_alloc(old_path);
|
||||
old_path_str = ref new Platform::String(old_path_wide);
|
||||
free(old_path_wide);
|
||||
|
||||
new_dir_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
fill_pathname_basedir(new_dir_path, new_path, PATH_MAX_LENGTH);
|
||||
fill_pathname_basedir(new_dir_path, new_path, sizeof(new_dir_path));
|
||||
new_dir_path_wide = utf8_to_utf16_string_alloc(new_dir_path);
|
||||
windowsize_path(new_dir_path_wide);
|
||||
new_dir_path_str = ref new Platform::String(new_dir_path_wide);
|
||||
free(new_dir_path_wide);
|
||||
free(new_dir_path);
|
||||
|
||||
new_file_name = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
fill_pathname_base(new_file_name, new_path, PATH_MAX_LENGTH);
|
||||
fill_pathname_base(new_file_name, new_path, sizeof(new_file_name));
|
||||
new_file_name_wide = utf8_to_utf16_string_alloc(new_file_name);
|
||||
new_file_name_str = ref new Platform::String(new_file_name_wide);
|
||||
free(new_file_name_wide);
|
||||
free(new_file_name);
|
||||
|
||||
retro_assert(!old_path_str->IsEmpty() && !new_dir_path_str->IsEmpty() && !new_file_name_str->IsEmpty());
|
||||
|
||||
@ -666,10 +665,14 @@ int retro_vfs_mkdir_impl(const char *dir)
|
||||
Platform::String^ parent_path_str;
|
||||
Platform::String^ dir_name_str;
|
||||
wchar_t *dir_name_wide, *parent_path_wide;
|
||||
char *dir_local, *tmp, *dir_name, *parent_path;
|
||||
char *dir_local, *tmp, *dir_name;
|
||||
char parent_path[PATH_MAX_LENGTH];
|
||||
char dir_name[PATH_MAX_LENGTH];
|
||||
if (!dir || !*dir)
|
||||
return -1;
|
||||
|
||||
dir_name[0] = '\0';
|
||||
|
||||
/* If the path ends with a slash, we have to remove
|
||||
* it for basename to work */
|
||||
dir_local = strdup(dir);
|
||||
@ -678,20 +681,16 @@ int retro_vfs_mkdir_impl(const char *dir)
|
||||
if (PATH_CHAR_IS_SLASH(*tmp))
|
||||
*tmp = 0;
|
||||
|
||||
dir_name = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
fill_pathname_base(dir_name, dir_local, PATH_MAX_LENGTH);
|
||||
fill_pathname_base(dir_name, dir_local, sizeof(dir_name));
|
||||
dir_name_wide = utf8_to_utf16_string_alloc(dir_name);
|
||||
dir_name_str = ref new Platform::String(dir_name_wide);
|
||||
free(dir_name_wide);
|
||||
free(dir_name);
|
||||
|
||||
parent_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
fill_pathname_parent_dir(parent_path, dir_local, PATH_MAX_LENGTH);
|
||||
fill_pathname_parent_dir(parent_path, dir_local, sizeof(parent_path));
|
||||
parent_path_wide = utf8_to_utf16_string_alloc(parent_path);
|
||||
windowsize_path(parent_path_wide);
|
||||
parent_path_str = ref new Platform::String(parent_path_wide);
|
||||
free(parent_path_wide);
|
||||
free(parent_path);
|
||||
|
||||
retro_assert(!dir_name_str->IsEmpty()
|
||||
&& !parent_path_str->IsEmpty());
|
||||
|
@ -967,22 +967,19 @@ static void stripes_update_thumbnail_path(void *data, unsigned i, char pos)
|
||||
|
||||
if (!string_is_empty(new_path))
|
||||
{
|
||||
char *tmp_new2 = (char*)
|
||||
malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
char tmp_new2[PATH_MAX_LENGTH];
|
||||
|
||||
tmp_new2[0] = '\0';
|
||||
|
||||
/* Append Named_Snaps/Named_Boxarts/Named_Titles */
|
||||
if (pos == 'R')
|
||||
fill_pathname_join(tmp_new2, new_path,
|
||||
stripes_thumbnails_ident('R'), PATH_MAX_LENGTH * sizeof(char));
|
||||
stripes_thumbnails_ident('R'), sizeof(tmp_new2));
|
||||
if (pos == 'L')
|
||||
fill_pathname_join(tmp_new2, new_path,
|
||||
stripes_thumbnails_ident('L'), PATH_MAX_LENGTH * sizeof(char));
|
||||
stripes_thumbnails_ident('L'), sizeof(tmp_new2));
|
||||
|
||||
strlcpy(new_path, tmp_new2,
|
||||
PATH_MAX_LENGTH * sizeof(char));
|
||||
free(tmp_new2);
|
||||
strlcpy(new_path, tmp_new2, sizeof(new_path));
|
||||
}
|
||||
|
||||
/* Scrub characters that are not cross-platform and/or violate the
|
||||
@ -992,9 +989,8 @@ static void stripes_update_thumbnail_path(void *data, unsigned i, char pos)
|
||||
*/
|
||||
if (!string_is_empty(stripes->thumbnail_content))
|
||||
{
|
||||
char tmp_new[PATH_MAX_LENGTH];
|
||||
char *scrub_char_pointer = NULL;
|
||||
char *tmp_new = (char*)
|
||||
malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
char *tmp = strdup(stripes->thumbnail_content);
|
||||
|
||||
tmp_new[0] = '\0';
|
||||
@ -1004,15 +1000,12 @@ static void stripes_update_thumbnail_path(void *data, unsigned i, char pos)
|
||||
|
||||
/* Look for thumbnail file with this scrubbed filename */
|
||||
|
||||
fill_pathname_join(tmp_new,
|
||||
new_path,
|
||||
tmp, PATH_MAX_LENGTH * sizeof(char));
|
||||
fill_pathname_join(tmp_new, new_path, tmp, sizeof(tmp_new));
|
||||
|
||||
if (!string_is_empty(tmp_new))
|
||||
strlcpy(new_path,
|
||||
tmp_new, sizeof(new_path));
|
||||
|
||||
free(tmp_new);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
@ -1053,8 +1046,7 @@ static void stripes_update_savestate_thumbnail_path(void *data, unsigned i)
|
||||
|| (string_is_equal(entry.label, "loadstate"))
|
||||
|| (string_is_equal(entry.label, "savestate"))))
|
||||
{
|
||||
size_t path_size = 8024 * sizeof(char);
|
||||
char *path = (char*)malloc(8204 * sizeof(char));
|
||||
char path[8024];
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
path[0] = '\0';
|
||||
@ -1064,16 +1056,16 @@ static void stripes_update_savestate_thumbnail_path(void *data, unsigned i)
|
||||
int state_slot = settings->ints.state_slot;
|
||||
|
||||
if (state_slot > 0)
|
||||
snprintf(path, path_size, "%s%d",
|
||||
snprintf(path, sizeof(path), "%s%d",
|
||||
global->name.savestate, state_slot);
|
||||
else if (state_slot < 0)
|
||||
fill_pathname_join_delim(path,
|
||||
global->name.savestate, "auto", '.', path_size);
|
||||
global->name.savestate, "auto", '.', sizeof(path));
|
||||
else
|
||||
strlcpy(path, global->name.savestate, path_size);
|
||||
strlcpy(path, global->name.savestate, sizeof(path));
|
||||
}
|
||||
|
||||
strlcat(path, ".png", path_size);
|
||||
strlcat(path, ".png", sizeof(path));
|
||||
|
||||
if (path_is_valid(path))
|
||||
{
|
||||
@ -1081,8 +1073,6 @@ static void stripes_update_savestate_thumbnail_path(void *data, unsigned i)
|
||||
free(stripes->savestate_thumbnail_file_path);
|
||||
stripes->savestate_thumbnail_file_path = strdup(path);
|
||||
}
|
||||
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1521,8 +1511,7 @@ static void stripes_list_switch_new(stripes_handle_t *stripes,
|
||||
|
||||
if (settings->bools.menu_dynamic_wallpaper_enable)
|
||||
{
|
||||
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
|
||||
char *path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
char path[PATH_MAX_LENGTH];
|
||||
char *tmp = string_replace_substring(stripes->title_name, "/", " ");
|
||||
|
||||
path[0] = '\0';
|
||||
@ -1533,14 +1522,14 @@ static void stripes_list_switch_new(stripes_handle_t *stripes,
|
||||
path,
|
||||
settings->paths.directory_dynamic_wallpapers,
|
||||
tmp,
|
||||
path_size);
|
||||
sizeof(path));
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
strlcat(path, ".png", path_size);
|
||||
strlcat(path, ".png", sizeof(path));
|
||||
|
||||
if (!path_is_valid(path))
|
||||
fill_pathname_application_special(path, path_size,
|
||||
fill_pathname_application_special(path, sizeof(path),
|
||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_BG);
|
||||
|
||||
if (!string_is_equal(path, stripes->bg_file_path))
|
||||
@ -1555,11 +1544,9 @@ static void stripes_list_switch_new(stripes_handle_t *stripes,
|
||||
stripes->bg_file_path = strdup(path);
|
||||
}
|
||||
}
|
||||
|
||||
free(path);
|
||||
}
|
||||
|
||||
end = file_list_get_size(list);
|
||||
end = file_list_get_size(list);
|
||||
|
||||
first = 0;
|
||||
last = end > 0 ? end - 1 : 0;
|
||||
@ -1944,25 +1931,20 @@ static void stripes_context_reset_horizontal_list(
|
||||
{
|
||||
struct texture_image ti;
|
||||
char sysname[256];
|
||||
char *iconpath = (char*)
|
||||
malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
char *texturepath = (char*)
|
||||
malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
char *content_texturepath = (char*)
|
||||
malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||
char iconpath[PATH_MAX_LENGTH];
|
||||
char texturepath[PATH_MAX_LENGTH];
|
||||
char content_texturepath[PATH_MAX_LENGTH];
|
||||
|
||||
iconpath[0] = sysname[0] =
|
||||
texturepath[0] = content_texturepath[0] = '\0';
|
||||
|
||||
fill_pathname_base_noext(sysname, path, sizeof(sysname));
|
||||
|
||||
fill_pathname_application_special(iconpath,
|
||||
PATH_MAX_LENGTH * sizeof(char),
|
||||
fill_pathname_application_special(iconpath, sizeof(iconpath),
|
||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS);
|
||||
|
||||
fill_pathname_join_concat(texturepath, iconpath, sysname,
|
||||
".png",
|
||||
PATH_MAX_LENGTH * sizeof(char));
|
||||
".png", sizeof(texturepath));
|
||||
|
||||
ti.width = 0;
|
||||
ti.height = 0;
|
||||
@ -1981,10 +1963,9 @@ static void stripes_context_reset_horizontal_list(
|
||||
image_texture_free(&ti);
|
||||
}
|
||||
|
||||
strlcat(iconpath, sysname, PATH_MAX_LENGTH * sizeof(char));
|
||||
strlcat(iconpath, sysname, sizeof(iconpath));
|
||||
fill_pathname_join_delim(content_texturepath, iconpath,
|
||||
"content.png", '-',
|
||||
PATH_MAX_LENGTH * sizeof(char));
|
||||
"content.png", '-', sizeof(content_texturepath));
|
||||
|
||||
if (image_texture_load(&ti, content_texturepath))
|
||||
{
|
||||
@ -1997,10 +1978,6 @@ static void stripes_context_reset_horizontal_list(
|
||||
|
||||
image_texture_free(&ti);
|
||||
}
|
||||
|
||||
free(iconpath);
|
||||
free(texturepath);
|
||||
free(content_texturepath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,8 @@ int cue_find_track(const char *cue_path, bool first,
|
||||
int rv;
|
||||
intfstream_info_t info;
|
||||
char *tmp_token = (char*)malloc(MAX_TOKEN_LEN);
|
||||
char *last_file = (char*)malloc(PATH_MAX_LENGTH + 1);
|
||||
char last_file[PATH_MAX_LENGTH];
|
||||
char cue_dir[PATH_MAX_LENGTH];
|
||||
intfstream_t *fd = NULL;
|
||||
int64_t last_index = -1;
|
||||
int64_t cand_index = -1;
|
||||
@ -503,10 +504,9 @@ int cue_find_track(const char *cue_path, bool first,
|
||||
uint64_t largest = 0;
|
||||
int64_t volatile file_size = -1;
|
||||
bool is_data = false;
|
||||
char *cue_dir = (char*)malloc(PATH_MAX_LENGTH);
|
||||
cue_dir[0] = '\0';
|
||||
cue_dir[0] = last_file[0] = '\0';
|
||||
|
||||
fill_pathname_basedir(cue_dir, cue_path, PATH_MAX_LENGTH);
|
||||
fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));
|
||||
|
||||
info.type = INTFSTREAM_FILE;
|
||||
fd = (intfstream_t*)intfstream_init(&info);
|
||||
@ -548,7 +548,7 @@ int cue_find_track(const char *cue_path, bool first,
|
||||
|
||||
get_token(fd, tmp_token, MAX_TOKEN_LEN);
|
||||
fill_pathname_join(last_file, cue_dir,
|
||||
tmp_token, PATH_MAX_LENGTH);
|
||||
tmp_token, sizeof(last_file));
|
||||
|
||||
file_size = intfstream_get_file_size(last_file);
|
||||
|
||||
@ -607,17 +607,13 @@ int cue_find_track(const char *cue_path, bool first,
|
||||
rv = 0;
|
||||
|
||||
clean:
|
||||
free(cue_dir);
|
||||
free(tmp_token);
|
||||
free(last_file);
|
||||
intfstream_close(fd);
|
||||
free(fd);
|
||||
return rv;
|
||||
|
||||
error:
|
||||
free(cue_dir);
|
||||
free(tmp_token);
|
||||
free(last_file);
|
||||
if (fd)
|
||||
{
|
||||
intfstream_close(fd);
|
||||
@ -629,12 +625,12 @@ error:
|
||||
bool cue_next_file(intfstream_t *fd,
|
||||
const char *cue_path, char *path, uint64_t max_len)
|
||||
{
|
||||
char cue_dir[PATH_MAX_LENGTH];
|
||||
bool rv = false;
|
||||
char *tmp_token = (char*)malloc(MAX_TOKEN_LEN);
|
||||
char *cue_dir = (char*)malloc(PATH_MAX_LENGTH);
|
||||
cue_dir[0] = '\0';
|
||||
|
||||
fill_pathname_basedir(cue_dir, cue_path, PATH_MAX_LENGTH);
|
||||
fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));
|
||||
|
||||
tmp_token[0] = '\0';
|
||||
|
||||
@ -649,7 +645,6 @@ bool cue_next_file(intfstream_t *fd,
|
||||
}
|
||||
}
|
||||
|
||||
free(cue_dir);
|
||||
free(tmp_token);
|
||||
return rv;
|
||||
}
|
||||
@ -728,22 +723,19 @@ int gdi_find_track(const char *gdi_path, bool first,
|
||||
/* Check for data track */
|
||||
if (!(mode == 0 && size == 2352))
|
||||
{
|
||||
char *last_file = (char*)malloc(PATH_MAX_LENGTH + 1);
|
||||
char *gdi_dir = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char last_file[PATH_MAX_LENGTH];
|
||||
char gdi_dir[PATH_MAX_LENGTH];
|
||||
|
||||
gdi_dir[0] = '\0';
|
||||
gdi_dir[0] = last_file[0] = '\0';
|
||||
|
||||
fill_pathname_basedir(gdi_dir, gdi_path, PATH_MAX_LENGTH);
|
||||
fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir));
|
||||
|
||||
fill_pathname_join(last_file,
|
||||
gdi_dir, tmp_token, PATH_MAX_LENGTH);
|
||||
gdi_dir, tmp_token, sizeof(last_file));
|
||||
file_size = intfstream_get_file_size(last_file);
|
||||
|
||||
if (file_size < 0)
|
||||
{
|
||||
free(gdi_dir);
|
||||
free(last_file);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((uint64_t)file_size > largest)
|
||||
{
|
||||
@ -753,14 +745,8 @@ int gdi_find_track(const char *gdi_path, bool first,
|
||||
largest = file_size;
|
||||
|
||||
if (first)
|
||||
{
|
||||
free(gdi_dir);
|
||||
free(last_file);
|
||||
goto clean;
|
||||
}
|
||||
}
|
||||
free(gdi_dir);
|
||||
free(last_file);
|
||||
}
|
||||
|
||||
/* Disc offset (not used?) */
|
||||
@ -813,11 +799,11 @@ bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
|
||||
/* File name */
|
||||
if (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
|
||||
{
|
||||
char *gdi_dir = (char*)malloc(PATH_MAX_LENGTH);
|
||||
char gdi_dir[PATH_MAX_LENGTH];
|
||||
|
||||
gdi_dir[0] = '\0';
|
||||
|
||||
fill_pathname_basedir(gdi_dir, gdi_path, PATH_MAX_LENGTH);
|
||||
fill_pathname_basedir(gdi_dir, gdi_path, sizeof(gdi_dir));
|
||||
|
||||
fill_pathname_join(path, gdi_dir, tmp_token, (size_t)max_len);
|
||||
|
||||
@ -825,8 +811,6 @@ bool gdi_next_file(intfstream_t *fd, const char *gdi_path,
|
||||
|
||||
/* Disc offset */
|
||||
get_token(fd, tmp_token, MAX_TOKEN_LEN);
|
||||
|
||||
free(gdi_dir);
|
||||
}
|
||||
|
||||
free(tmp_token);
|
||||
|
Loading…
x
Reference in New Issue
Block a user