Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Dec 2009 18:18:46 +0000 (UTC)
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r200442 - in head: tools/regression/usr.bin tools/regression/usr.bin/comm usr.bin/comm
Message-ID:  <200912121818.nBCIIkUg059941@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jh
Date: Sat Dec 12 18:18:46 2009
New Revision: 200442
URL: http://svn.freebsd.org/changeset/base/200442

Log:
  Don't read the newline character to line buffer because lines are passed
  to wcscoll(3). Newline characters could cause incorrect results when
  comparing lines.
  
  Also, if an input line didn't contain a newline character, it was
  omitted from the output. According to my interpretation, SUSv3 requires
  that the newline is always printed.
  
  Add regression tests for the cases. [1]
  
  PR:		bin/140976
  Submitted by:	D'Arcy Cain (original version) [1]
  Approved by:	trasz (mentor)

Added:
  head/tools/regression/usr.bin/comm/
  head/tools/regression/usr.bin/comm/Makefile   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.00.out   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.00a.in   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.00b.in   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.01.out   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.01a.in   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.01b.in   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.02.out   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.02a.in   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.02b.in   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.sh   (contents, props changed)
  head/tools/regression/usr.bin/comm/regress.t   (contents, props changed)
Modified:
  head/tools/regression/usr.bin/Makefile
  head/usr.bin/comm/comm.c

Modified: head/tools/regression/usr.bin/Makefile
==============================================================================
--- head/tools/regression/usr.bin/Makefile	Sat Dec 12 18:04:50 2009	(r200441)
+++ head/tools/regression/usr.bin/Makefile	Sat Dec 12 18:18:46 2009	(r200442)
@@ -1,5 +1,5 @@
 # $FreeBSD$
 
-SUBDIR=	calendar file2c join jot m4 printf sed tr uudecode uuencode xargs lastcomm
+SUBDIR=	calendar comm file2c join jot m4 printf sed tr uudecode uuencode xargs lastcomm
 
 .include <bsd.subdir.mk>

Added: head/tools/regression/usr.bin/comm/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/Makefile	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+all:
+	@m4 ${.CURDIR}/../regress.m4 ${.CURDIR}/regress.sh | sh /dev/stdin ${.CURDIR}

Added: head/tools/regression/usr.bin/comm/regress.00.out
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.00.out	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,2 @@
+a b
+e f g

Added: head/tools/regression/usr.bin/comm/regress.00a.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.00a.in	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,5 @@
+a b
+c d
+e f
+e f g
+h i

Added: head/tools/regression/usr.bin/comm/regress.00b.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.00b.in	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,2 @@
+a b
+e f g

Added: head/tools/regression/usr.bin/comm/regress.01.out
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.01.out	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,2 @@
+a	b
+e	f	g

Added: head/tools/regression/usr.bin/comm/regress.01a.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.01a.in	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,5 @@
+a	b
+c	d
+e	f
+e	f	g
+h	i

Added: head/tools/regression/usr.bin/comm/regress.01b.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.01b.in	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,2 @@
+a	b
+e	f	g

Added: head/tools/regression/usr.bin/comm/regress.02.out
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.02.out	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,5 @@
+a
+b
+		c
+	d
+	e

Added: head/tools/regression/usr.bin/comm/regress.02a.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.02a.in	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,3 @@
+a
+b
+c
\ No newline at end of file

Added: head/tools/regression/usr.bin/comm/regress.02b.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.02b.in	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,3 @@
+c
+d
+e
\ No newline at end of file

Added: head/tools/regression/usr.bin/comm/regress.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.sh	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+LC_ALL=C; export LC_ALL
+
+echo 1..3
+
+REGRESSION_START($1)
+
+REGRESSION_TEST(`00', `comm -12 regress.00a.in regress.00b.in')
+REGRESSION_TEST(`01', `comm -12 regress.01a.in regress.01b.in')
+REGRESSION_TEST(`02', `comm regress.02a.in regress.02b.in')
+
+REGRESSION_END()

Added: head/tools/regression/usr.bin/comm/regress.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/usr.bin/comm/regress.t	Sat Dec 12 18:18:46 2009	(r200442)
@@ -0,0 +1,6 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+m4 ../regress.m4 regress.sh | sh

Modified: head/usr.bin/comm/comm.c
==============================================================================
--- head/usr.bin/comm/comm.c	Sat Dec 12 18:04:50 2009	(r200441)
+++ head/usr.bin/comm/comm.c	Sat Dec 12 18:18:46 2009	(r200442)
@@ -163,7 +163,7 @@ main(int argc, char *argv[])
 		if (!comp) {
 			read1 = read2 = 1;
 			if (col3 != NULL)
-				(void)printf("%ls%ls", col3, line1);
+				(void)printf("%ls%ls\n", col3, line1);
 			continue;
 		}
 
@@ -172,12 +172,12 @@ main(int argc, char *argv[])
 			read1 = 1;
 			read2 = 0;
 			if (col1 != NULL)
-				(void)printf("%ls%ls", col1, line1);
+				(void)printf("%ls%ls\n", col1, line1);
 		} else {
 			read1 = 0;
 			read2 = 1;
 			if (col2 != NULL)
-				(void)printf("%ls%ls", col2, line2);
+				(void)printf("%ls%ls\n", col2, line2);
 		}
 	}
 	exit(0);
@@ -190,19 +190,16 @@ getline(wchar_t *buf, size_t *buflen, FI
 	wint_t ch;
 
 	bufpos = 0;
-	do {
-		if ((ch = getwc(fp)) != WEOF) {
-			if (bufpos + 2 >= *buflen) {
-				*buflen = *buflen * 2;
-				buf = reallocf(buf, *buflen * sizeof(*buf));
-				if (buf == NULL)
-					return (NULL);
-			}
-			buf[bufpos++] = ch;
+	while ((ch = getwc(fp)) != WEOF && ch != '\n') {
+		if (bufpos + 1 >= *buflen) {
+			*buflen = *buflen * 2;
+			buf = reallocf(buf, *buflen * sizeof(*buf));
+			if (buf == NULL)
+				return (NULL);
 		}
-	} while (ch != WEOF && ch != '\n');
-	if (bufpos + 1 != *buflen)
-		buf[bufpos] = '\0';
+		buf[bufpos++] = ch;
+	}
+	buf[bufpos] = '\0';
 
 	return (bufpos != 0 || ch == '\n' ? buf : NULL);
 }
@@ -212,7 +209,7 @@ show(FILE *fp, const char *fn, const wch
 {
 
 	do {
-		(void)printf("%ls%ls", offset, buf);
+		(void)printf("%ls%ls\n", offset, buf);
 	} while ((buf = getline(buf, buflen, fp)) != NULL);
 	if (ferror(fp))
 		err(1, "%s", fn);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200912121818.nBCIIkUg059941>