sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 515525997c634c1abd6ec3e661a02f5c11858c00
parent 0b87cd4c61ab14972ccb3931483560ebde222eb6
Author: FRIGN <dev@frign.de>
Date:   Thu, 10 Mar 2016 20:12:56 +0100

Fix linecmp() to return correct values

Diffstat:
Mlibutil/linecmp.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libutil/linecmp.c b/libutil/linecmp.c @@ -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;