linecmp: Handle NUL bytes properly

Test case:

if [ "$(printf 'a\na\0b' | ./sort -u)" = "$(printf 'a\na\0b')" ] ; then
	echo pass
else
	echo fail
fi
This commit is contained in:
Michael Forney 2016-05-14 18:56:55 -07:00 committed by sin
parent a944b682a6
commit 8ca79a2993
1 changed files with 2 additions and 9 deletions

View File

@ -10,15 +10,8 @@ linecmp(struct line *a, struct line *b)
{
int res = 0;
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;
}
}
if (!(res = memcmp(a->data, b->data, MIN(a->len, b->len))))
res = a->len - b->len;
return res;
}