Fix bug in parser that causes a crash with a bad option
authorJens Axboe <jens.axboe@oracle.com>
Wed, 19 Nov 2008 11:31:43 +0000 (12:31 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 19 Nov 2008 11:31:43 +0000 (12:31 +0100)
The priority sorting would crash if it failed to lookup both
of the passed in options.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
parse.c

diff --git a/parse.c b/parse.c
index 456e3bafb54f91c19c060bf42c1e152e21448467..8a2e6f215f0ba1f3df53abb2e3e9774a7180af17 100644 (file)
--- 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;
 {
        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);
 
        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);
 
        free(s1);
        free(s2);
-       return ret;
+       return prio2 - prio1;
 }
 
 void sort_options(char **opts, struct fio_option *options, int num_opts)
 }
 
 void sort_options(char **opts, struct fio_option *options, int num_opts)