pgrep: Off by one in realloc in option handling

The loop that parses options has a of by one bug where the realloc
adds one byte, instead of one list element.  This is exposed when
you try things like:
  pgrep -t,,,,

Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
Vadim Kaushan 2015-04-03 18:17:08 +11:00 committed by Craig Small
parent fd77ca1dc6
commit 6ed8cf3444

View File

@ -160,7 +160,7 @@ static struct el *split_list (const char *restrict str, int (*convert)(const cha
if (i == size) { if (i == size) {
size = size * 5 / 4 + 4; size = size * 5 / 4 + 4;
/* add 1 because slot zero is a count */ /* add 1 because slot zero is a count */
list = xrealloc (list, 1 + size * sizeof *list); list = xrealloc (list, (1 + size) * sizeof *list);
} }
sep_pos = strchr (ptr, ','); sep_pos = strchr (ptr, ',');
if (sep_pos) if (sep_pos)