sbase

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

commit 8ca79a2993e572beb7be56be1b0b95482c3a2431
parent a944b682a694b4e7900c94d6550845f8d52af574
Author: Michael Forney <mforney@mforney.org>
Date:   Sat May 14 18:56:55 -0700

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

Diffstat:
libutil/linecmp.c | 11++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/libutil/linecmp.c b/libutil/linecmp.c @@ -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; }