From bd94cc6e8bbe61d34c2853fdd551029d467cfcf8 Mon Sep 17 00:00:00 2001 From: eddyem Date: Mon, 30 Jan 2017 14:53:43 +0300 Subject: [PATCH] fix bug with arguments sorting in parseargs.c --- getopt/cmdlnopts/parseargs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/getopt/cmdlnopts/parseargs.c b/getopt/cmdlnopts/parseargs.c index 62c3808..a05a02a 100644 --- a/getopt/cmdlnopts/parseargs.c +++ b/getopt/cmdlnopts/parseargs.c @@ -340,12 +340,12 @@ static int argsort(const void *a1, const void *a2){ int s1 = o1->val, s2 = o2->val; int *f1 = o1->flag, *f2 = o2->flag; // check if both options has short arg - if(f1 == NULL && f2 == NULL){ // both have short arg + if(f1 == NULL && f2 == NULL && s1 && s2){ // both have short arg return (s1 - s2); - }else if(f1 != NULL && f2 != NULL){ // both don't have short arg - sort by long + }else if((f1 != NULL || !s1) && (f2 != NULL || !s2)){ // both don't have short arg - sort by long return strcmp(l1, l2); }else{ // only one have short arg -- return it - if(f2) return -1; // a1 have short - it is 'lesser' + if(f2 || !s2) return -1; // a1 have short - it is 'lesser' else return 1; } }