mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-08-30 17:58:37 +08:00
libobs/util: Simplify implementation of os_get_path_extension
To avoid a false use-after-free warning from GCC's -Wuse-after-free option, revise the implementation without using memory allocation.
This commit is contained in:
+10
-21
@@ -654,28 +654,17 @@ int os_mkdirs(const char *dir)
|
||||
|
||||
const char *os_get_path_extension(const char *path)
|
||||
{
|
||||
struct dstr temp;
|
||||
size_t pos = 0;
|
||||
char *period;
|
||||
char *slash;
|
||||
for (size_t pos = strlen(path); pos > 0; pos--) {
|
||||
switch (path[pos - 1]) {
|
||||
case '.':
|
||||
return path + pos - 1;
|
||||
case '/':
|
||||
case '\\':
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!path[0])
|
||||
return NULL;
|
||||
|
||||
dstr_init_copy(&temp, path);
|
||||
dstr_replace(&temp, "\\", "/");
|
||||
|
||||
slash = strrchr(temp.array, '/');
|
||||
period = strrchr(temp.array, '.');
|
||||
if (period)
|
||||
pos = (size_t)(period - temp.array);
|
||||
|
||||
dstr_free(&temp);
|
||||
|
||||
if (!period || slash > period)
|
||||
return NULL;
|
||||
|
||||
return path + pos;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline bool valid_string(const char *str)
|
||||
|
||||
Reference in New Issue
Block a user