From b2ebca4a6057efc09607362398ff64fb8fc67633 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 5 Feb 2012 21:10:53 +0100 Subject: [PATCH] pgrep: fix potential null derefences [smatch scan] pgrep.c:137 split_list(19) error: potential null derefence 'list'. pgrep.c:540 select_procs(106) error: potential null derefence 'list'. Signed-off-by: Sami Kerola --- pgrep.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pgrep.c b/pgrep.c index b5d72365..d4c2665b 100644 --- a/pgrep.c +++ b/pgrep.c @@ -134,7 +134,7 @@ static struct el *split_list (const char *restrict str, int (*convert)(const cha if (sep_pos) *sep_pos = 0; // Use ++i instead of i++ because slot zero is a count - if (!convert (ptr, &list[++i])) + if (list && !convert (ptr, &list[++i])) exit (EXIT_USAGE); if (sep_pos) ptr = sep_pos + 1; @@ -535,12 +535,14 @@ static struct el * select_procs (int *num) size = size * 5 / 4 + 4; list = xrealloc(list, size * sizeof *list); } - if (opt_long || opt_echo) { + if (list && (opt_long || opt_echo)) { char buff[5096]; // FIXME list[matches].num = task.XXXID; list[matches++].str = xstrdup (cmd); - } else { + } else if (list) { list[matches++].num = task.XXXID; + } else { + xerrx(EXIT_FAILURE, _("internal error")); } }