From a6a87d63d00902d3d17ac5e932c5b0a51d3b5bb2 Mon Sep 17 00:00:00 2001 From: paco Date: Wed, 20 Jun 2018 18:25:28 +0200 Subject: [PATCH] lib: uninitialized variable (2) (Coverity 1469898) Previous correction (2c2d5cb397c140c05ad81e8c79273bd3af13b595) was not enough, so now it is ensured that the argument shift is not negative nor zero. Signed-off-by: F. Aragon --- lib/command.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/command.c b/lib/command.c index a8e61c6bb4..0f38cdb83f 100644 --- a/lib/command.c +++ b/lib/command.c @@ -261,8 +261,11 @@ void print_version(const char *progname) char *argv_concat(struct cmd_token **argv, int argc, int shift) { - int cnt = argc - shift; - const char *argstr[cnt]; + int cnt = MAX(argc - shift, 0); + const char *argstr[cnt + 1]; + + if (!cnt) + return NULL; for (int i = 0; i < cnt; i++) argstr[i] = argv[i + shift]->arg; -- 2.39.5