Skip to content

Commit

Permalink
Fix memory allocation in parser
Browse files Browse the repository at this point in the history
The set_value function was incorrectly using sizeof (char *) when
allocation and reallocating memory.
  • Loading branch information
rohara committed Jan 16, 2014
1 parent cba49f2 commit 2a3bb34
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,9 @@ set_value(vector_t *strvec)
str = vector_slot(strvec, i);
len += strlen(str);
if (!alloc)
alloc =
(char *) MALLOC(sizeof (char *) *
(len + 1));
alloc = (char *) MALLOC(len + 1);
else {
alloc =
REALLOC(alloc, sizeof (char *) * (len + 1));
alloc = (char *) REALLOC(alloc, (len + 1));
tmp = vector_slot(strvec, i-1);
if (*str != '"' && *tmp != '"')
strncat(alloc, " ", 1);
Expand All @@ -397,7 +394,7 @@ set_value(vector_t *strvec)
strncat(alloc, str, strlen(str));
}
} else {
alloc = MALLOC(sizeof (char *) * (size + 1));
alloc = (char *) MALLOC(size + 1);
memcpy(alloc, str, size);
}
return alloc;
Expand Down

0 comments on commit 2a3bb34

Please sign in to comment.