fix: allocate tree-printing strings by their length (#1961)

Automated security fix generated by OrbisAI Security
This commit is contained in:
Anupam Mediratta
2026-10-10 16:48:26 +05:30
committed by GitHub
parent 5b279d48b3
commit 4eba6da393

View File

@@ -64,8 +64,8 @@ typedef struct Trunk {
Trunk *newTrunk(Trunk *prev, char *str) {
Trunk *trunk = (Trunk *)malloc(sizeof(Trunk));
trunk->prev = prev;
trunk->str = (char *)malloc(sizeof(char) * 10);
strcpy(trunk->str, str);
trunk->str = (char *)malloc(strlen(str) + 1);
snprintf(trunk->str, strlen(str) + 1, "%s", str);
return trunk;
}