sbase

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

commit 1798e5c3999b759ff150f937a06df581bfe745fe
parent 2fea92166391362145771066f956a1bbddec3023
Author: Eivind Uggedal <eivind@uggedal.com>
Date:   Fri Mar 11 15:06:18 +0000

uniq: always store previous line length

A bug was introduced in the NUL support refactor leading to
the length of the previous line only being saved if the
previous line was shorter than the current line. If triggered
this lead to copying too much data into the previous line buffer.

Behavior before:

	printf '1234\na\n' | ./uniq
	1234
	a
	4

Behavior after:

	printf '1234\na\n' | ./uniq
	1234
	a

Diffstat:
uniq.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/uniq.c b/uniq.c @@ -62,9 +62,9 @@ uniqline(FILE *ofp, struct line *l) if (l) { if (!prevl.data || l->len >= prevl.len) { - prevl.len = l->len; - prevl.data = erealloc(prevl.data, prevl.len); + prevl.data = erealloc(prevl.data, l->len); } + prevl.len = l->len; memcpy(prevl.data, l->data, prevl.len); prevoff = loff; }