From ba35f0de93a3a1f1d3cab1e36ba04a027266d028 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 19 Jul 2022 23:23:37 +0200 Subject: [PATCH] (file_path.c) Do away with trivial strlen checks (checked if return number was <= 2/>= 2, instead check first two characters of the string directly instead for NULL --- libretro-common/file/file_path.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index c8a12e18dd..bcdfe55e91 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -526,8 +526,8 @@ void fill_str_dated_filename(char *out_filename, void path_basedir(char *path) { char *last = NULL; - - if (strlen(path) < 2) + /* was strlen(path) < 2 before */ + if (!path || path[0] == '\0' || path[1] == '\0') return; if ((last = find_last_slash(path))) @@ -805,8 +805,15 @@ size_t path_relative_to(char *out, #ifdef _WIN32 /* For different drives, return absolute path */ - if (strlen(path) >= 2 && strlen(base) >= 2 - && path[1] == ':' && base[1] == ':' + if ( + path + && base + && path[0] != '\0' + && path[1] != '\0' /* was strlen(path) >= 2 before */ + && base[0] != '\0' + && base[1] != '\0' /* was strlen(base) >= 2 before */ + && path[1] == ':' + && base[1] == ':' && path[0] != base[0]) return strlcpy(out, path, size); #endif @@ -1151,7 +1158,8 @@ void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpat void path_basedir_wrapper(char *path) { char *last = NULL; - if (strlen(path) < 2) + /* was strlen(path) < 2 before */ + if (!path || path[0] == '\0' || path[1] == '\0') return; #ifdef HAVE_COMPRESSION