Cut down on more unnecessary strlens

This commit is contained in:
twinaphex 2020-05-24 17:25:52 +02:00
parent 64c30610f5
commit 376b62e8fa
4 changed files with 52 additions and 36 deletions

View File

@ -122,26 +122,28 @@ static bool m3u_file_load(m3u_file_t *m3u_file)
/* Parse lines of file */
for (i = 0; i < lines->size; i++)
{
size_t m3u_size;
const char *line = lines->elems[i].data;
if (string_is_empty(line))
continue;
/* Determine line 'type' */
m3u_size = strlen(M3U_FILE_NONSTD_LABEL);
/* > '#LABEL:' */
if (!strncmp(
line, M3U_FILE_NONSTD_LABEL,
strlen(M3U_FILE_NONSTD_LABEL)))
m3u_size))
{
/* Label is the string to the right
* of '#LABEL:' */
const char *label = line + strlen(M3U_FILE_NONSTD_LABEL);
const char *label = line + m3u_size;
if (!string_is_empty(label))
{
strlcpy(
entry_label, line + strlen(M3U_FILE_NONSTD_LABEL),
entry_label, line + m3u_size,
sizeof(entry_label));
string_trim_whitespace(entry_label);
}

View File

@ -101,8 +101,7 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
continue;
}
len = strlen(line);
len = strlen(line);
command = line;
media_skip_spaces(&command, len);
@ -332,7 +331,8 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
sector_size = 2048;
}
if (!memcmp(buf + offset, "SEGADISCSYSTEM", strlen("SEGADISCSYSTEM")))
if (!memcmp(buf + offset, "SEGADISCSYSTEM",
STRLEN_CONST("SEGADISCSYSTEM")))
{
const char *title_pos = NULL;
const char *serial_pos = NULL;
@ -366,7 +366,8 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
else
strlcpy(info->serial, "N/A", sizeof(info->serial));
}
else if (!memcmp(buf + offset, "SEGA SEGASATURN", strlen("SEGA SEGASATURN")))
else if (!memcmp(buf + offset, "SEGA SEGASATURN",
STRLEN_CONST("SEGA SEGASATURN")))
{
const char *title_pos = NULL;
const char *serial_pos = NULL;
@ -420,7 +421,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
else
strlcpy(info->release_date, "N/A", sizeof(info->release_date));
}
else if (!memcmp(buf + offset, "SEGA SEGAKATANA", strlen("SEGA SEGAKATANA")))
else if (!memcmp(buf + offset, "SEGA SEGAKATANA", STRLEN_CONST("SEGA SEGAKATANA")))
{
const char *title_pos = NULL;
const char *serial_pos = NULL;

View File

@ -137,11 +137,11 @@ void retro_vfs_file_open_cdrom(
if (!string_is_equal_noncase(ext, "cue") && !string_is_equal_noncase(ext, "bin"))
return;
if (path_len >= strlen("drive1-track01.bin"))
if (path_len >= STRLEN_CONST("drive1-track01.bin"))
{
if (!memcmp(path, "drive", strlen("drive")))
if (!memcmp(path, "drive", STRLEN_CONST("drive")))
{
if (!memcmp(path + 6, "-track", strlen("-track")))
if (!memcmp(path + 6, "-track", STRLEN_CONST("-track")))
{
if (sscanf(path + 12, "%02u", (unsigned*)&stream->cdrom.cur_track))
{
@ -154,9 +154,9 @@ void retro_vfs_file_open_cdrom(
}
}
if (path_len >= strlen("drive1.cue"))
if (path_len >= STRLEN_CONST("drive1.cue"))
{
if (!memcmp(path, "drive", strlen("drive")))
if (!memcmp(path, "drive", STRLEN_CONST("drive")))
{
if (path[5] >= '0' && path[5] <= '9')
{
@ -209,9 +209,9 @@ void retro_vfs_file_open_cdrom(
if (!string_is_equal_noncase(ext, "cue") && !string_is_equal_noncase(ext, "bin"))
return;
if (path_len >= strlen("d:/drive-track01.bin"))
if (path_len >= STRLEN_CONST("d:/drive-track01.bin"))
{
if (!memcmp(path + 1, ":/drive-track", strlen(":/drive-track")))
if (!memcmp(path + 1, ":/drive-track", STRLEN_CONST(":/drive-track")))
{
if (sscanf(path + 14, "%02u", (unsigned*)&stream->cdrom.cur_track))
{
@ -223,9 +223,9 @@ void retro_vfs_file_open_cdrom(
}
}
if (path_len >= strlen("d:/drive.cue"))
if (path_len >= STRLEN_CONST("d:/drive.cue"))
{
if (!memcmp(path + 1, ":/drive", strlen(":/drive")))
if (!memcmp(path + 1, ":/drive", STRLEN_CONST(":/drive")))
{
if ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z'))
{

View File

@ -58,6 +58,7 @@ static bool connmanctl_tether_status(void)
/* Returns true if the tethering is active
* false when tethering is not active
*/
size_t ln_size;
FILE *command_file = NULL;
char ln[3] = {0};
@ -78,8 +79,9 @@ static bool connmanctl_tether_status(void)
fgets(ln, sizeof(ln), command_file);
if (ln[strlen(ln)-1] == '\n')
ln[strlen(ln)-1] = '\0';
ln_size = strlen(ln)-1;
if (ln[ln_size] == '\n')
ln[ln_size] = '\0';
RARCH_LOG("[CONNMANCTL] Tether Status: command: \"%s\", output: \"%s\"\n",
command, ln);
@ -113,8 +115,9 @@ static void connmanctl_tether_toggle(bool switch_on, char* apname, char* passkey
while (fgets(output, sizeof(output), command_file))
{
if (output[strlen(output)-1] == '\n')
output[strlen(output)-1] = '\0';
size_t output_size = strlen(output) - 1;
if (output[output_size] == '\n')
output[output_size] = '\0';
RARCH_LOG("[CONNMANCTL] Tether toggle: output: \"%s\"\n",
output);
@ -349,6 +352,7 @@ static bool connmanctl_connect_ssid(unsigned idx, const char* passphrase)
static void connmanctl_get_connected_ssid(char* ssid, size_t buffersize)
{
size_t ssid_size;
/* Stores the SSID of the currently connected Wi-Fi
* network in ssid
*/
@ -373,12 +377,14 @@ static void connmanctl_get_connected_ssid(char* ssid, size_t buffersize)
pclose(command_file);
if (strlen(ssid) > 0)
if (ssid[strlen(ssid)-1] == '\n')
ssid[strlen(ssid)-1] = '\0';
ssid_size = strlen(ssid) - 1;
if ((ssid_size + 1) > 0)
if (ssid[ssid_size] == '\n')
ssid[ssid_size] = '\0';
RARCH_LOG("[CONNMANCTL] Get Connected SSID: command: \"%s\", output: \"%s\"\n",
command, strlen(ssid) ? ssid : "<nothing_found>");
command, (ssid_size + 1) ? ssid : "<nothing_found>");
}
static void connmanctl_get_connected_servicename(char* servicename, size_t buffersize)
@ -416,11 +422,14 @@ static void connmanctl_get_connected_servicename(char* servicename, size_t buffe
while (fgets(temp, buffersize, command_file))
{
if (strlen(temp) > 0)
if (temp[strlen(temp)-1] == '\n')
temp[strlen(temp)-1] = '\0';
size_t ln_size;
size_t temp_size = strlen(temp) - 1;
if (strlen(temp) == 0)
if ((temp_size + 1) > 0)
if (temp[temp_size] == '\n')
temp[temp_size] = '\0';
if ((temp_size + 1) == 0)
{
RARCH_WARN("[CONNMANCTL] Service name empty.\n");
continue;
@ -439,9 +448,10 @@ static void connmanctl_get_connected_servicename(char* servicename, size_t buffe
service_file = popen(command, "r");
fgets(ln, sizeof(ln), service_file);
ln_size = strlen(ln) - 1;
if (ln[strlen(ln)-1] == '\n')
ln[strlen(ln)-1] = '\0';
if (ln[ln_size] == '\n')
ln[ln_size] = '\0';
pclose(service_file);
@ -549,11 +559,13 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
while (fgets(ln, sizeof(ln), command_file))
{
size_t ln_size = strlen(ln) - 1;
i++;
if (strlen(ln) > 1)
if ((ln_size + 1) > 1)
{
if (ln[strlen(ln)-1] == '\n')
ln[strlen(ln)-1] = '\0';
if (ln[ln_size] == '\n')
ln[ln_size] = '\0';
if (i == 1)
{
@ -634,8 +646,9 @@ static void connmanctl_tether_start_stop(bool start, char* configfile)
while (fgets(ln, sizeof(ln), command_file))
{
if (ln[strlen(ln)-1] == '\n')
ln[strlen(ln)-1] = '\0';
size_t ln_size = strlen(ln) - 1;
if (ln[ln_size] == '\n')
ln[ln_size] = '\0';
RARCH_LOG("[CONNMANCTL] Tether start stop: output: \"%s\"\n",
ln);