diff --git a/configuration.c b/configuration.c index 9ee344988f..0d50897886 100644 --- a/configuration.c +++ b/configuration.c @@ -5697,7 +5697,11 @@ void input_config_parse_joy_axis( && tmp[3] == '\0' ) bind->joyaxis = AXIS_NONE; - else if (strlen(tmp) >= 2 && (*tmp == '+' || *tmp == '-')) + else if + ( tmp[0] != '\0' + && tmp[1] != '\0' + && (*tmp == '+' + || *tmp == '-')) { int i_axis = (int)strtol(tmp + 1, NULL, 0); if (*tmp == '+') diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index a779c2cb79..8df58aec6a 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -950,13 +950,13 @@ static bool accessibility_speak_macos(int speed, else { /* child process: replace process with the say command */ - if (strlen(language_speaker)> 0) + if (language_speaker && language_speaker[0] != '\0') { char* cmd[] = {"say", "-v", NULL, NULL, "-r", NULL, NULL}; - cmd[2] = language_speaker; - cmd[3] = (char *) speak_text; - cmd[5] = speeds[speed-1]; + cmd[2] = language_speaker; + cmd[3] = (char *) speak_text; + cmd[5] = speeds[speed-1]; execvp("say", cmd); } else diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c index 6c4b5970b8..57d64bb376 100644 --- a/frontend/drivers/platform_win32.c +++ b/frontend/drivers/platform_win32.c @@ -950,7 +950,7 @@ static bool create_win32_process(char* cmd, const char * input) { STARTUPINFO si; HANDLE rd = NULL; - bool ret; + bool ret = false; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); memset(&g_pi, 0, sizeof(g_pi)); @@ -959,11 +959,13 @@ static bool create_win32_process(char* cmd, const char * input) { DWORD dummy; HANDLE wr; - if (!CreatePipe(&rd, &wr, NULL, strlen(input))) return false; + size_t input_len = strlen(input); + if (!CreatePipe(&rd, &wr, NULL, input_len)) + return false; SetHandleInformation(rd, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); - WriteFile(wr, input, strlen(input), &dummy, NULL); + WriteFile(wr, input, input_len, &dummy, NULL); CloseHandle(wr); si.dwFlags |= STARTF_USESTDHANDLES; @@ -974,7 +976,8 @@ static bool create_win32_process(char* cmd, const char * input) ret = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &g_pi); - if (rd) CloseHandle(rd); + if (rd) + CloseHandle(rd); return ret; } @@ -987,20 +990,17 @@ static bool is_narrator_running_windows(void) if (USE_POWERSHELL) { - if (pi_set == false) + if (!pi_set) return false; if (GetExitCodeProcess(g_pi.hProcess, &status)) - { if (status == STILL_ACTIVE) return true; - } return false; } #ifdef HAVE_NVDA else if (USE_NVDA) { - long res; - res = nvdaController_testIfRunning_func(); + long res = nvdaController_testIfRunning_func(); if (res != 0) { @@ -1010,7 +1010,7 @@ static bool is_narrator_running_windows(void) RARCH_ERR("Error communicating with NVDA\n"); USE_POWERSHELL = true; USE_NVDA = false; - return false; + return false; } return false; } @@ -1059,7 +1059,7 @@ static bool accessibility_speak_windows(int speed, { const char * template_lang = "powershell.exe -NoProfile -WindowStyle Hidden -Command \"Add-Type -AssemblyName System.Speech; $synth = New-Object System.Speech.Synthesis.SpeechSynthesizer; $synth.SelectVoice(\\\"%s\\\"); $synth.Rate = %s; $synth.Speak($input);\""; const char * template_nolang = "powershell.exe -NoProfile -WindowStyle Hidden -Command \"Add-Type -AssemblyName System.Speech; $synth = New-Object System.Speech.Synthesis.SpeechSynthesizer; $synth.Rate = %s; $synth.Speak($input);\""; - if (strlen(language) > 0) + if (language && language[0] != '\0') snprintf(cmd, sizeof(cmd), template_lang, language, speeds[speed-1]); else snprintf(cmd, sizeof(cmd), template_nolang, speeds[speed-1]); diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index bcdfe55e91..727cf2875b 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -526,7 +526,6 @@ void fill_str_dated_filename(char *out_filename, void path_basedir(char *path) { char *last = NULL; - /* was strlen(path) < 2 before */ if (!path || path[0] == '\0' || path[1] == '\0') return; @@ -809,9 +808,9 @@ size_t path_relative_to(char *out, path && base && path[0] != '\0' - && path[1] != '\0' /* was strlen(path) >= 2 before */ + && path[1] != '\0' && base[0] != '\0' - && base[1] != '\0' /* was strlen(base) >= 2 before */ + && base[1] != '\0' && path[1] == ':' && base[1] == ':' && path[0] != base[0]) @@ -1158,7 +1157,6 @@ void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpat void path_basedir_wrapper(char *path) { char *last = NULL; - /* was strlen(path) < 2 before */ if (!path || path[0] == '\0' || path[1] == '\0') return; diff --git a/network/drivers_wifi/connmanctl.c b/network/drivers_wifi/connmanctl.c index 7fcb8dce62..26e725384f 100644 --- a/network/drivers_wifi/connmanctl.c +++ b/network/drivers_wifi/connmanctl.c @@ -78,15 +78,16 @@ static void connmanctl_refresh_services(connman_t *connman) while (fgets(line, 512, serv_file)) { int i; - struct string_list* list = NULL; + size_t ssid_len; wifi_network_info_t entry; - size_t len = strlen(line); + struct string_list* list = NULL; + size_t len = strlen(line); if (len > 0 && line[len-1] == '\n') line[--len] = '\0'; /* Parse lines directly and store net info directly */ memset(&entry, 0, sizeof(entry)); - entry.connected = (line[2] == 'R' || line[2] == 'O'); + entry.connected = (line[2] == 'R' || line[2] == 'O'); entry.saved_password = (line[0] == '*'); /* connmanctl services outputs a 4 character prefixed lines, @@ -95,8 +96,7 @@ static void connmanctl_refresh_services(connman_t *connman) * '*A0 SSID some_unique_id' * ' SSID some_another_unique_id' */ - list = string_split(&line[4], " "); - if (!list) + if (!(list = string_split(&line[4], " "))) break; if (list->size == 0) @@ -107,8 +107,8 @@ static void connmanctl_refresh_services(connman_t *connman) strlcat(entry.ssid, list->elems[i].data, sizeof(entry.ssid)); strlcat(entry.ssid, " ", sizeof(entry.ssid)-1); } - if (strlen(entry.ssid)) - entry.ssid[strlen(entry.ssid)-1] = 0; + if ((ssid_len = strlen(entry.ssid)) > 0) + entry.ssid[ssid_len - 1] = 0; /* Store the connman network id here, for later */ strlcpy(entry.netid, list->elems[list->size-1].data, sizeof(entry.netid)); @@ -162,7 +162,7 @@ static bool connmanctl_tether_status(connman_t *connman) fgets(ln, sizeof(ln), command_file); - ln_size = strlen(ln)-1; + ln_size = strlen(ln) - 1; if (ln[ln_size] == '\n') ln[ln_size] = '\0'; @@ -343,6 +343,7 @@ static bool connmanctl_connect_ssid( if (!netinfo->saved_password) { + size_t ssid_len; FILE *settings_file = fopen(settings_path, "w"); if (!settings_file) return false; @@ -350,7 +351,8 @@ static bool connmanctl_connect_ssid( fprintf(settings_file, "Name=%s\n", netinfo->ssid); fprintf(settings_file, "SSID="); - for (i = 0; i < strlen(netinfo->ssid); i++) + ssid_len = strlen(netinfo->ssid); + for (i = 0; i < ssid_len; i++) fprintf(settings_file, "%02x", (unsigned int) netinfo->ssid[i]); fprintf(settings_file, "\n"); diff --git a/network/drivers_wifi/nmcli.c b/network/drivers_wifi/nmcli.c index afe9b823fc..a093bdbf62 100644 --- a/network/drivers_wifi/nmcli.c +++ b/network/drivers_wifi/nmcli.c @@ -111,7 +111,7 @@ static void nmcli_scan(void *data) memset(&entry, 0, sizeof(entry)); string_trim_whitespace(line); - if (strlen(line) < 1) + if (!line || line[0] == '\0') continue; if (line[0] == '*') diff --git a/retroarch.c b/retroarch.c index ef0a517095..d0afbea32f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -647,7 +647,7 @@ struct string_list *string_list_new_special(enum string_list_type type, "cut -f3 | " "sort", "r"); - if (zones_file != NULL) + if (zones_file) { char zone_desc[TIMEZONE_LENGTH]; while (fgets(zone_desc, TIMEZONE_LENGTH, zones_file)) @@ -658,7 +658,7 @@ struct string_list *string_list_new_special(enum string_list_type type, if (zone_desc[--zone_desc_len] == '\n') zone_desc[zone_desc_len] = '\0'; - if (strlen(zone_desc) > 0) + if (zone_desc && zone_desc[0] != '\0') { const char *opt = zone_desc; *len += strlen(opt) + 1; @@ -4537,7 +4537,7 @@ static bool retroarch_parse_input_and_config( string_trim_whitespace_left(p_rarch->launch_arguments); string_trim_whitespace_right(p_rarch->launch_arguments); - first_run = false; + first_run = false; /* Command line interface is only considered * to be 'active' (i.e. used by a third party)