Skip to content

Commit

Permalink
sh.func.c: allocate memory properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Krush206 committed Nov 22, 2023
1 parent dc756c0 commit 836268e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sh.func.c
Original file line number Diff line number Diff line change
Expand Up @@ -2714,16 +2714,16 @@ dofunction(Char **v, struct command *t)
for (i = 0; v[i]; i++)
;

vh = xmalloc((i + 2) * sizeof(Char *));
vh = xmalloc(sizeof(Char [i + 2]));
vh[i + 1] = NULL;

for (j = i--; i; i--, j--) {
vh[j] = xmalloc(((Strlen(v[i]) + 1) * sizeof(Char)));
vh[j] = xmalloc(sizeof(Char [Strlen(v[i]) + 1]));
Strcpy(vh[j], v[i]);
}
vh[1] = xmalloc(Strlen(ffile) + 1);
vh[1] = xmalloc(sizeof (Char [Strlen(ffile) + 1]));
Strcpy(vh[1], ffile);
*vh = xmalloc(Strlen(*v) + 1);
*vh = xmalloc(sizeof (Char [Strlen(*v) + 1]));
Strcpy(*vh, *v);

if (fargv) {
Expand Down

0 comments on commit 836268e

Please sign in to comment.