mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-19 11:31:26 +01:00
39992: setarrvalue: Allocate a correctly-sized array.
No memory was lost; the array was allocated with room for one (char *) element more than was required.
This commit is contained in:
parent
6e1684e332
commit
f35198d837
2 changed files with 13 additions and 2 deletions
|
@ -1,5 +1,8 @@
|
|||
2016-11-20 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
||||
* 39992: Src/params.c: setarrvalue: Allocate a correctly-sized
|
||||
array.
|
||||
|
||||
* unposted (after 39952): Src/Zle/zle_params.c: Restore C89
|
||||
compatibility.
|
||||
|
||||
|
|
12
Src/params.c
12
Src/params.c
|
@ -2654,8 +2654,13 @@ setarrvalue(Value v, char **val)
|
|||
v->end = v->start;
|
||||
|
||||
post_assignment_length = v->start + arrlen(val);
|
||||
if (v->end <= pre_assignment_length)
|
||||
post_assignment_length += pre_assignment_length - v->end + 1;
|
||||
if (v->end < pre_assignment_length) {
|
||||
/*
|
||||
* Allocate room for array elements between the end of the slice `v'
|
||||
* and the original array's end.
|
||||
*/
|
||||
post_assignment_length += pre_assignment_length - v->end;
|
||||
}
|
||||
|
||||
p = new = (char **) zalloc(sizeof(char *)
|
||||
* (post_assignment_length + 1));
|
||||
|
@ -2671,6 +2676,9 @@ setarrvalue(Value v, char **val)
|
|||
*p++ = ztrdup(*q++);
|
||||
*p = NULL;
|
||||
|
||||
DPUTS2(p - new != post_assignment_length, "setarrvalue: wrong allocation: %d 1= %lu",
|
||||
post_assignment_length, (unsigned long)(p - new));
|
||||
|
||||
v->pm->gsu.a->setfn(v->pm, new);
|
||||
|
||||
/* Ownership of all strings has been
|
||||
|
|
Loading…
Reference in a new issue