Fix linecmp() to return correct values

This commit is contained in:
FRIGN 2016-03-10 20:12:56 +01:00 committed by sin
parent 0b87cd4c61
commit 515525997c
1 changed files with 8 additions and 4 deletions

View File

@ -10,10 +10,14 @@ linecmp(struct line *a, struct line *b)
{ {
int res = 0; int res = 0;
if (!(res = memcmp(a->data, b->data, MIN(a->len, b->len))) && if (!(res = memcmp(a->data, b->data, MIN(a->len, b->len)))) {
a->len != b->len) { if (a->len > b->len) {
res = a->data[MIN(a->len, b->len) - 1] - res = a->data[b->len];
b->data[MIN(a->len, b->len) - 1]; } else if (b->len > a->len) {
res = -b->data[a->len];
} else {
res = 0;
}
} }
return res; return res;