Fix undefined behavior in strncpy()
call
`strncpy()`'s pointer parameters are marked `restrict`, but when `file_browser_reload_directory_content()` was being called to reload the directory it already had open, it would try to copy its path buffer to itself, causing undefined behavior.
This commit is contained in:
parent
544009db92
commit
3793609e39
@ -345,7 +345,8 @@ media_init(struct media *media)
|
||||
static void
|
||||
file_browser_reload_directory_content(struct file_browser *browser, const char *path)
|
||||
{
|
||||
strncpy(browser->directory, path, MAX_PATH_LEN);
|
||||
const size_t path_len = strlen(path) + 1;
|
||||
memmove(browser->directory, path, MIN(path_len, MAX_PATH_LEN));
|
||||
browser->directory[MAX_PATH_LEN - 1] = 0;
|
||||
dir_free_list(browser->files, browser->file_count);
|
||||
dir_free_list(browser->directories, browser->dir_count);
|
||||
|
Loading…
Reference in New Issue
Block a user