fix(compiler): resolve string truncation and use-after-free warnings

- In stk_module_load: Use memcpy with explicit length check instead of strncpy
- In platform_directory_init_scan: Same fix for directory scanning
- In stk_module_realloc_memory: Replace realloc with malloc+memcpy approach
  to avoid potential use-after-free issues and compiler warnings
- All changes maintain same functionality with improved safety
This commit is contained in:
2026-01-31 21:08:38 +01:00
parent 4bd1f00b5b
commit 49ae5ed75e
2 changed files with 63 additions and 29 deletions
+7 -1
View File
@@ -340,6 +340,7 @@ char (*platform_directory_init_scan(const char *dir_path, size_t *out_count))
struct dirent *e;
struct stat st;
char f[STK_PATH_MAX_OS];
size_t name_len;
d = opendir(dir_path);
if (!d)
@@ -381,7 +382,12 @@ char (*platform_directory_init_scan(const char *dir_path, size_t *out_count))
if (stat(f, &st) != 0 || !S_ISREG(st.st_mode))
goto fill_loop;
strncpy(list[i++], e->d_name, STK_PATH_MAX - 1);
name_len = strlen(e->d_name);
if (name_len >= STK_PATH_MAX) {
name_len = STK_PATH_MAX - 1;
}
memcpy(list[i++], e->d_name, name_len);
list[i - 1][name_len] = '\0';
goto fill_loop;
create_and_exit: