diff --git a/command.c b/command.c index ef7b4d59f81..93cb11bf6df 100644 --- a/command.c +++ b/command.c @@ -421,9 +421,8 @@ bool command_get_config_param(command_t *cmd, const char* arg) _len += strlcpy(reply + _len, arg, sizeof(reply) - _len); reply[ _len] = ' '; reply[++_len] = '\0'; - _len = strlcpy(reply + _len, value, sizeof(reply) - _len); - /* TODO/FIXME - replace strlen(reply) by _len? check if they are equal */ - cmd->replier(cmd, reply, strlen(reply)); + _len += strlcpy(reply + _len, value, sizeof(reply) - _len); + cmd->replier(cmd, reply, _len); return true; } @@ -526,8 +525,7 @@ command_t* command_uds_new(void) command_t *cmd; command_uds_t *subcmd; struct sockaddr_un addr; - const char *sp = "retroarch/cmd"; - socklen_t addrsz = offsetof(struct sockaddr_un, sun_path) + strlen(sp) + 1; + socklen_t addrsz = offsetof(struct sockaddr_un, sun_path) + STRLEN_CONST("retroarch/cmd") + 1; int fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) return NULL; @@ -535,7 +533,7 @@ command_t* command_uds_new(void) /* use an abstract socket for simplicity */ memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strcpy(&addr.sun_path[1], sp); + strcpy(&addr.sun_path[1], "retroarch/cmd"); if (bind(fd, (struct sockaddr*)&addr, addrsz) < 0 || listen(fd, MAX_USER_CONNECTIONS) < 0) @@ -824,8 +822,7 @@ bool command_version(command_t *cmd, const char* arg) size_t _len = strlcpy(reply, PACKAGE_VERSION, sizeof(reply)); reply[ _len] = '\n'; reply[++_len] = '\0'; - /* TODO/FIXME - replace strlen(reply) by _len? Check if they are equal */ - cmd->replier(cmd, reply, strlen(reply)); + cmd->replier(cmd, reply, _len); return true; } @@ -913,6 +910,7 @@ static uint8_t *command_memory_get_pointer( bool command_get_status(command_t *cmd, const char* arg) { + size_t _len; char reply[4096]; uint8_t flags = content_get_flags(); @@ -937,13 +935,13 @@ bool command_get_status(command_t *cmd, const char* arg) if (!system_id) system_id = runloop_st->system.info.library_name; - snprintf(reply, sizeof(reply), "GET_STATUS %s %s,%s,crc32=%x\n", + _len = snprintf(reply, sizeof(reply), "GET_STATUS %s %s,%s,crc32=%x\n", status, system_id, content_name, content_crc32); } else - strlcpy(reply, "GET_STATUS CONTENTLESS", sizeof(reply)); + _len = strlcpy(reply, "GET_STATUS CONTENTLESS", sizeof(reply)); - cmd->replier(cmd, reply, strlen(reply)); + cmd->replier(cmd, reply, _len); return true; } @@ -957,7 +955,7 @@ bool command_read_memory(command_t *cmd, const char *arg) unsigned int nbytes = 0; unsigned int alloc_size = 0; unsigned int address = -1; - size_t len = 0; + size_t _len = 0; unsigned int max_bytes = 0; runloop_state_t *runloop_st = runloop_state_get_ptr(); const rarch_system_info_t* sys_info= &runloop_st->system; @@ -981,12 +979,12 @@ bool command_read_memory(command_t *cmd, const char *arg) snprintf(reply_at + 3 * i, 4, " %02X", data[i]); reply_at[3 * nbytes] = '\n'; - len = reply_at + 3 * nbytes + 1 - reply; + _len = reply_at + 3 * nbytes + 1 - reply; } else - len = strlen(reply); + _len = strlen(reply); - cmd->replier(cmd, reply, len); + cmd->replier(cmd, reply, _len); free(reply); return true; } diff --git a/configuration.c b/configuration.c index 84c99b1c9a6..e6d89a94795 100644 --- a/configuration.c +++ b/configuration.c @@ -1435,33 +1435,32 @@ const char *config_get_all_timezones(void) return char_list_new_special(STRING_LIST_TIMEZONES, NULL); } -static void load_timezone(char *setting) +static void load_timezone(char *s) { char haystack[TIMEZONE_LENGTH+32]; - static char *needle = "TIMEZONE="; - size_t needle_len = strlen(needle); - RFILE *tzfp = filestream_open(LAKKA_TIMEZONE_PATH, + static char *needle = "TIMEZONE="; + RFILE *tzfp = filestream_open(LAKKA_TIMEZONE_PATH, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); - if (tzfp) { - char *start = NULL; + char *start = NULL; filestream_gets(tzfp, haystack, sizeof(haystack)-1); filestream_close(tzfp); - start = strstr(haystack, needle); - - if (start) - strlcpy(setting, start + needle_len, TIMEZONE_LENGTH); + if ((start = strstr(haystack, needle))) + { + size_t needle_len = STRLEN_CONST("TIMEZONE="); + strlcpy(s, start + needle_len, TIMEZONE_LENGTH); + } else - strlcpy(setting, DEFAULT_TIMEZONE, TIMEZONE_LENGTH); + strlcpy(s, DEFAULT_TIMEZONE, TIMEZONE_LENGTH); } else - strlcpy(setting, DEFAULT_TIMEZONE, TIMEZONE_LENGTH); + strlcpy(s, DEFAULT_TIMEZONE, TIMEZONE_LENGTH); - config_set_timezone(setting); + config_set_timezone(s); } #endif @@ -5744,6 +5743,7 @@ bool input_remapping_load_file(void *data, const char *path) **/ bool input_remapping_save_file(const char *path) { + size_t _len; bool ret; unsigned i, j; char remap_file_dir[PATH_MAX_LENGTH]; @@ -5761,12 +5761,12 @@ bool input_remapping_save_file(const char *path) return false; /* Create output directory, if required */ - strlcpy(remap_file_dir, path, sizeof(remap_file_dir)); - path_parent_dir(remap_file_dir, strlen(remap_file_dir)); + _len = strlcpy(remap_file_dir, path, sizeof(remap_file_dir)); + path_parent_dir(remap_file_dir, _len); - if (!string_is_empty(remap_file_dir) && - !path_is_directory(remap_file_dir) && - !path_mkdir(remap_file_dir)) + if ( !string_is_empty(remap_file_dir) + && !path_is_directory(remap_file_dir) + && !path_mkdir(remap_file_dir)) return false; /* Attempt to load file */ diff --git a/retroarch.c b/retroarch.c index 0124eb70eef..0ec848bba1a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1460,7 +1460,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; menu_ctx_drivers[i]; i++) { const char *opt = menu_ctx_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(menu_ctx_drivers[i]->ident) + 1; /* Don't allow the user to set menu driver to "null" using the UI. * Can prevent the user from locking him/herself out of the program. */ @@ -1473,7 +1473,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; camera_drivers[i]; i++) { const char *opt = camera_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(camera_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1483,7 +1483,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; bluetooth_drivers[i]; i++) { const char *opt = bluetooth_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(bluetooth_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1494,7 +1494,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; wifi_drivers[i]; i++) { const char *opt = wifi_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(wifi_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1504,7 +1504,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; location_drivers[i]; i++) { const char *opt = location_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(location_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1513,7 +1513,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; audio_drivers[i]; i++) { const char *opt = audio_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(audio_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1523,7 +1523,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; microphone_drivers[i]; i++) { const char *opt = microphone_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(microphone_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1533,7 +1533,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; audio_resampler_driver_find_handle(i); i++) { const char *opt = audio_resampler_driver_find_ident(i); - *len += strlen(opt) + 1; + *len += STRLEN_CONST(audio_resampler_driver_find_ident(i)) + 1; string_list_append(s, opt, attr); } @@ -1542,7 +1542,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; video_drivers[i]; i++) { const char *opt = video_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(video_drivers[i]->ident) + 1; /* Don't allow the user to set video driver to "null" using the UI. * Can prevent the user from locking him/herself out of the program. */ @@ -1554,7 +1554,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; input_drivers[i]; i++) { const char *opt = input_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(input_drivers[i]->ident) + 1; /* Don't allow the user to set input driver to "null" using the UI. * Can prevent the user from locking him/herself out of the program. */ @@ -1567,7 +1567,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; hid_drivers[i]; i++) { const char *opt = hid_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STLREN_CONST(hid_drivers[i]->ident) + 1; /* Don't allow the user to set input HID driver to "null" using the UI. * Can prevent the user from locking him/herself out of the program. */ @@ -1580,7 +1580,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; joypad_drivers[i]; i++) { const char *opt = joypad_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(joypad_drivers[i]->ident) + 1; /* Don't allow the user to set input joypad driver to "null" using the UI. * Can prevent the user from locking him/herself out of the program. */ @@ -1592,7 +1592,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; record_drivers[i]; i++) { const char *opt = record_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(record_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1601,7 +1601,7 @@ struct string_list *string_list_new_special(enum string_list_type type, for (i = 0; midi_driver_find_handle(i); i++) { const char *opt = midi_drivers[i]->ident; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(midi_drivers[i]->ident) + 1; string_list_append(s, opt, attr); } @@ -1610,7 +1610,7 @@ struct string_list *string_list_new_special(enum string_list_type type, case STRING_LIST_TIMEZONES: { const char *opt = DEFAULT_TIMEZONE; - *len += strlen(opt) + 1; + *len += STRLEN_CONST(DEFAULT_TIMEZONE) + 1; string_list_append(s, opt, attr); FILE *zones_file = popen("grep -v ^# /usr/share/zoneinfo/zone.tab | " @@ -5490,7 +5490,7 @@ static void retroarch_parse_input_libretro_path(const char *path) _len = strlcpy(tmp_path, path, sizeof(tmp_path)); if (!string_ends_with_size(tmp_path, "_libretro", - strlen(tmp_path), STRLEN_CONST("_libretro"))) + _len, STRLEN_CONST("_libretro"))) strlcpy(tmp_path + _len, "_libretro", sizeof(tmp_path) - _len);