mirror of
https://github.com/krahets/hello-algo.git
synced 2026-10-28 19:24:21 +08:00
fix: allocate tree-printing strings by their length (#1961)
Automated security fix generated by OrbisAI Security
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user