aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2018-05-11 21:00:59 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2018-05-27 15:12:47 -0700
commit2416abc367513f0277b66556b3c499e7bc9cf01e (patch)
tree7b3497f5a5720ced9e53e665575257b103001ed8
parent1064148713b2e6984e0e5d2926ce2853a6aa96d2 (diff)
vendor.c: fix vendor sort
Fix a really stupid sort function I wrote for 60b9f3360930296c0f3e8b04672b8bf7468bedcb. Now actually does what that commit claims to do. I think I must have just sketched it out and then forgot to go back and correct it. It's weird that it happened to fix the one result I was testing for. Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r--hardinfo/vendor.c9
-rw-r--r--includes/vendor.h2
2 files changed, 6 insertions, 5 deletions
diff --git a/hardinfo/vendor.c b/hardinfo/vendor.c
index 86705e10..f73781c3 100644
--- a/hardinfo/vendor.c
+++ b/hardinfo/vendor.c
@@ -121,11 +121,12 @@ static GSList *vendor_list = NULL;
/* sort the vendor list by length of match_string,
* LONGEST first */
gint vendor_sort (gconstpointer a, gconstpointer b) {
+ const Vendor *ap = a, *bp = b;
int la = 0, lb = 0;
- if (a) la = strlen(a);
- if (b) lb = strlen(b);
- if (a == b) return 0;
- if (a > b) return -1;
+ if (ap && ap->match_string) la = strlen(ap->match_string);
+ if (bp && bp->match_string) lb = strlen(bp->match_string);
+ if (la == lb) return 0;
+ if (la > lb) return -1;
return 1;
}
diff --git a/includes/vendor.h b/includes/vendor.h
index 21d52562..021f4e78 100644
--- a/includes/vendor.h
+++ b/includes/vendor.h
@@ -22,7 +22,7 @@
typedef struct _Vendor Vendor;
struct _Vendor {
char *match_string;
- int match_case; /* 0 = ignore case, 1 = match case*/
+ int match_case; /* 0 = ignore case, 1 = match case */
char *name;
char *url;
};