mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 18:32:44 +00:00
Some string simplifications - don't NULL terminate if we pass
string to strlcpy and/or a file_path function using strlcpy under the hood - don't do strlcpy for trivial setting of 2/3 char strings
This commit is contained in:
parent
ddd9544a4f
commit
a6a4b845a4
@ -635,14 +635,15 @@ static bool win32_browser(
|
||||
char new_title[PATH_MAX];
|
||||
char new_file[32768];
|
||||
|
||||
new_title[0] = '\0';
|
||||
new_file[0] = '\0';
|
||||
|
||||
if (!string_is_empty(title))
|
||||
strlcpy(new_title, title, sizeof(new_title));
|
||||
else
|
||||
new_title[0] = '\0';
|
||||
|
||||
if (filename && *filename)
|
||||
strlcpy(new_file, filename, sizeof(new_file));
|
||||
else
|
||||
new_file[0] = '\0';
|
||||
|
||||
/* OPENFILENAME.lpstrFilters is actually const,
|
||||
* so this cast should be safe */
|
||||
@ -2345,12 +2346,8 @@ void win32_update_title(void)
|
||||
if (window)
|
||||
{
|
||||
char title[128];
|
||||
|
||||
title[0] = '\0';
|
||||
|
||||
video_driver_get_window_title(title, sizeof(title));
|
||||
update_title_wait = g_win32_refresh_rate;
|
||||
|
||||
if (title[0])
|
||||
window->set_title(&main_window, title);
|
||||
}
|
||||
|
@ -203,31 +203,32 @@ static void xdg_screensaver_inhibit(Window wnd)
|
||||
{
|
||||
int ret;
|
||||
char cmd[64];
|
||||
char title[128];
|
||||
|
||||
cmd[0] = '\0';
|
||||
title[0] = '\0';
|
||||
|
||||
RARCH_LOG("[X11]: Suspending screensaver (X11, xdg-screensaver).\n");
|
||||
|
||||
if (g_x11_dpy && g_x11_win)
|
||||
{
|
||||
char title[128];
|
||||
size_t title_len;
|
||||
/* Make sure the window has a title, even if it's a bogus one, otherwise
|
||||
* xdg-screensaver will fail and report to stderr, framing RA for its bug.
|
||||
* A single space character is used so that the title bar stays visibly
|
||||
* the same, as if there's no title at all. */
|
||||
video_driver_get_window_title(title, sizeof(title));
|
||||
if (strlen(title) == 0)
|
||||
snprintf(title, sizeof(title), " ");
|
||||
if ((title_len = strlen(title)) == 0)
|
||||
{
|
||||
title[0] = ' ';
|
||||
title[1] = '\0';
|
||||
}
|
||||
XChangeProperty(g_x11_dpy, g_x11_win, XA_WM_NAME, XA_STRING,
|
||||
8, PropModeReplace, (const unsigned char*) title,
|
||||
strlen(title));
|
||||
8, PropModeReplace, (const unsigned char*) title, title_len);
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "xdg-screensaver suspend 0x%x", (int)wnd);
|
||||
|
||||
ret = system(cmd);
|
||||
if (ret == -1)
|
||||
if ((ret = system(cmd)) == -1)
|
||||
{
|
||||
xdg_screensaver_available = false;
|
||||
RARCH_WARN("Failed to launch xdg-screensaver.\n");
|
||||
@ -519,18 +520,15 @@ static void x11_handle_key_event(unsigned keycode, XEvent *event, XIC ic, bool f
|
||||
keybuf[0] = '\0';
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
status = 0;
|
||||
|
||||
/* XwcLookupString doesn't seem to work. */
|
||||
num = Xutf8LookupString(ic, &event->xkey, keybuf,
|
||||
ARRAY_SIZE(keybuf), &keysym, &status);
|
||||
|
||||
/* libc functions need UTF-8 locale to work properly,
|
||||
* which makes mbrtowc a bit impractical.
|
||||
*
|
||||
* Use custom UTF8 -> UTF-32 conversion. */
|
||||
num = utf8_conv_utf32(chars, ARRAY_SIZE(chars), keybuf, num);
|
||||
#else
|
||||
(void)ic;
|
||||
num = XLookupString(&event->xkey, keybuf,
|
||||
sizeof(keybuf), &keysym, NULL); /* ASCII only. */
|
||||
for (i = 0; i < num; i++)
|
||||
@ -584,7 +582,7 @@ bool x11_alive(void *data)
|
||||
/* IMPORTANT - Get keycode before XFilterEvent
|
||||
because the event is localizated after the call */
|
||||
keycode = event.xkey.keycode;
|
||||
filter = XFilterEvent(&event, g_x11_win);
|
||||
filter = XFilterEvent(&event, g_x11_win);
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
@ -769,11 +767,7 @@ bool x11_connect(void)
|
||||
void x11_update_title(void *data)
|
||||
{
|
||||
char title[128];
|
||||
|
||||
title[0] = '\0';
|
||||
|
||||
video_driver_get_window_title(title, sizeof(title));
|
||||
|
||||
if (title[0])
|
||||
XChangeProperty(g_x11_dpy, g_x11_win, XA_WM_NAME, XA_STRING,
|
||||
8, PropModeReplace, (const unsigned char*)title,
|
||||
|
@ -3080,8 +3080,6 @@ void config_read_keybinds_conf(void *data)
|
||||
if (!btn || !prefix)
|
||||
continue;
|
||||
|
||||
str[0] = '\0';
|
||||
|
||||
fill_pathname_join_delim(str, prefix, btn, '_', sizeof(str));
|
||||
|
||||
/* Clear old mapping bit */
|
||||
@ -5675,8 +5673,8 @@ void input_keyboard_event(bool down, unsigned code,
|
||||
|
||||
if (say_char)
|
||||
{
|
||||
char c = (char) character;
|
||||
*say_char = c;
|
||||
char c = (char) character;
|
||||
*say_char = c;
|
||||
say_char[1] = '\0';
|
||||
|
||||
if (character == 127 || character == 8)
|
||||
|
@ -104,15 +104,13 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts,
|
||||
char new_path[PATH_MAX_LENGTH];
|
||||
const char *delim;
|
||||
|
||||
delim = path_get_archive_delim(userdata->archive_path);
|
||||
|
||||
if (delim)
|
||||
if ((delim = path_get_archive_delim(userdata->archive_path)))
|
||||
{
|
||||
if (!string_is_equal_noncase(userdata->current_file_path, delim + 1))
|
||||
if (!string_is_equal_noncase(
|
||||
userdata->current_file_path, delim + 1))
|
||||
return 1; /* keep searching for the right file */
|
||||
}
|
||||
|
||||
new_path[0] = '\0';
|
||||
if (userdata->extraction_directory)
|
||||
fill_pathname_join(new_path, userdata->extraction_directory,
|
||||
path_basename(name), sizeof(new_path));
|
||||
@ -120,7 +118,6 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts,
|
||||
fill_pathname_resolve_relative(new_path, userdata->archive_path,
|
||||
path_basename(name), sizeof(new_path));
|
||||
|
||||
|
||||
if (file_archive_perform_mode(new_path,
|
||||
valid_exts, cdata, cmode, csize, size,
|
||||
checksum, userdata))
|
||||
@ -141,25 +138,18 @@ static int file_archive_parse_file_init(file_archive_transfer_t *state,
|
||||
char path[PATH_MAX_LENGTH];
|
||||
char *last = NULL;
|
||||
|
||||
path[0] = '\0';
|
||||
|
||||
strlcpy(path, file, sizeof(path));
|
||||
|
||||
last = (char*)path_get_archive_delim(path);
|
||||
if ((last = (char*)path_get_archive_delim(path)))
|
||||
*last = '\0';
|
||||
|
||||
if (last)
|
||||
*last = '\0';
|
||||
|
||||
state->backend = file_archive_get_file_backend(path);
|
||||
if (!state->backend)
|
||||
if (!(state->backend = file_archive_get_file_backend(path)))
|
||||
return -1;
|
||||
|
||||
state->archive_file = filestream_open(path,
|
||||
RETRO_VFS_FILE_ACCESS_READ,
|
||||
RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||
|
||||
/* Failed to open archive. */
|
||||
if (!state->archive_file)
|
||||
if (!(state->archive_file = filestream_open(path,
|
||||
RETRO_VFS_FILE_ACCESS_READ,
|
||||
RETRO_VFS_FILE_ACCESS_HINT_NONE)))
|
||||
return -1;
|
||||
|
||||
state->archive_size = filestream_get_size(state->archive_file);
|
||||
@ -648,16 +638,12 @@ const struct file_archive_file_backend* file_archive_get_file_backend(const char
|
||||
const char *file_ext = NULL;
|
||||
char *last = NULL;
|
||||
|
||||
newpath[0] = '\0';
|
||||
|
||||
strlcpy(newpath, path, sizeof(newpath));
|
||||
|
||||
last = (char*)path_get_archive_delim(newpath);
|
||||
if ((last = (char*)path_get_archive_delim(newpath)))
|
||||
*last = '\0';
|
||||
|
||||
if (last)
|
||||
*last = '\0';
|
||||
|
||||
file_ext = path_get_extension(newpath);
|
||||
file_ext = path_get_extension(newpath);
|
||||
|
||||
#ifdef HAVE_7ZIP
|
||||
if (string_is_equal_noncase(file_ext, "7z"))
|
||||
|
@ -381,10 +381,10 @@ void net_http_urlencode(char **dest, const char *source)
|
||||
void net_http_urlencode_full(char *dest,
|
||||
const char *source, size_t size)
|
||||
{
|
||||
char url_domain[256];
|
||||
char url_path[PATH_MAX_LENGTH];
|
||||
size_t buf_pos = 0;
|
||||
char *tmp = NULL;
|
||||
char url_domain[256] = {0};
|
||||
char url_path[PATH_MAX_LENGTH] = {0};
|
||||
int count = 0;
|
||||
|
||||
strlcpy(url_path, source, sizeof(url_path));
|
||||
|
@ -807,7 +807,10 @@ static int explore_action_sublabel_spacer(
|
||||
* unnecessarily blank out the fallback
|
||||
* core title text in the sublabel area */
|
||||
if (string_is_equal(menu_driver, "ozone"))
|
||||
strlcpy(s, " ", len);
|
||||
{
|
||||
s[0] = ' ';
|
||||
s[1] = '\0';
|
||||
}
|
||||
|
||||
return 1; /* 1 means it'll never change and can be cached */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user