From: Jens Axboe Date: Wed, 19 Nov 2008 11:31:43 +0000 (+0100) Subject: Fix bug in parser that causes a crash with a bad option X-Git-Tag: fio-1.24~42 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=8cdabc1df71ec546d47ba4eb1190b8c7b6e62f9a;ds=sidebyside Fix bug in parser that causes a crash with a bad option The priority sorting would crash if it failed to lookup both of the passed in options. Signed-off-by: Jens Axboe --- diff --git a/parse.c b/parse.c index 456e3baf..8a2e6f21 100644 --- a/parse.c +++ b/parse.c @@ -487,22 +487,23 @@ static int opt_cmp(const void *p1, const void *p2) { struct fio_option *o1, *o2; char *s1, *s2, *foo; - int ret; + int prio1, prio2; s1 = strdup(*((char **) p1)); s2 = strdup(*((char **) p2)); o1 = get_option(s1, fio_options, &foo); o2 = get_option(s2, fio_options, &foo); - - if ((!o1 && o2) || (o1 && !o2)) - ret = 0; - else - ret = o2->prio - o1->prio; + + prio1 = prio2 = 0; + if (o1) + prio1 = o1->prio; + if (o2) + prio2 = o2->prio; free(s1); free(s2); - return ret; + return prio2 - prio1; } void sort_options(char **opts, struct fio_option *options, int num_opts)