This commit is contained in:
Your Name 2023-10-16 20:29:24 +03:00
parent b5819fbc96
commit b917633313

View File

@ -39,13 +39,14 @@ int rmtree(const char *path) {
if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, "..")) if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
continue; continue;
size_t len = strlen(path) + strlen(ep->d_name) + 2;
char *full_path = malloc(strlen(path) + strlen(ep->d_name) + 1); char *full_path = malloc(strlen(path) + strlen(ep->d_name) + 1);
if (full_path == NULL) { if (full_path == NULL) {
fprintf(stderr, "rm: malloc() returned NULL\n"); fprintf(stderr, "rm: malloc() returned NULL\n");
return 1; return 1;
} }
sprintf(full_path, "%s/%s", path, ep->d_name); snprintf(full_path, len, "%s/%s", path, ep->d_name);
rmtree(full_path); rmtree(full_path);
free(full_path); free(full_path);