[hackers] [sbase] Fix linecmp() to return correct values || FRIGN

From: <git_AT_suckless.org>
Date: Fri, 11 Mar 2016 16:38:45 +0100 (CET)

commit 515525997c634c1abd6ec3e661a02f5c11858c00
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Thu Mar 10 20:12:56 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Fri Mar 11 15:38:36 2016 +0000

    Fix linecmp() to return correct values

diff --git a/libutil/linecmp.c b/libutil/linecmp.c
index cba27d1..f5a6cf9 100644
--- a/libutil/linecmp.c
+++ b/libutil/linecmp.c
_AT_@ -10,10 +10,14 @@ linecmp(struct line *a, struct line *b)
 {
         int res = 0;
 
- if (!(res = memcmp(a->data, b->data, MIN(a->len, b->len))) &&
- a->len != b->len) {
- res = a->data[MIN(a->len, b->len) - 1] -
- b->data[MIN(a->len, b->len) - 1];
+ if (!(res = memcmp(a->data, b->data, MIN(a->len, b->len)))) {
+ if (a->len > b->len) {
+ res = a->data[b->len];
+ } else if (b->len > a->len) {
+ res = -b->data[a->len];
+ } else {
+ res = 0;
+ }
         }
 
         return res;
Received on Fri Mar 11 2016 - 16:38:45 CET

This archive was generated by hypermail 2.3.0 : Fri Mar 11 2016 - 16:48:16 CET