NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/55891: /usr/bin/nl breaks POSIX compatibility



>Number:         55891
>Category:       bin
>Synopsis:       /usr/bin/nl breaks POSIX compatibility
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 22 08:55:00 +0000 2020
>Originator:     Kobayashi Takashi
>Release:        9.1
>Organization:
AIIT
>Environment:
NetBSD localhost 9.1 NetBSD 9.1 (GENERIC) #0: Sun Oct 18 19:24:30 UTC 2020  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
In POSIX, the "STDOUT" section of nl requires the following:
> When line numbers are suppressed for a portion of the page; the <separator> is also suppressed.

However, it is not actually suppressed.
>How-To-Repeat:
$ yes '' | head | nl -s@
      @
      @
      @
      @
      @
      @
      @
      @
      @
      @

>Fix:
Maybe...

--- nl.c	2020-12-15 14:49:35.652652227 -0800
+++ nl.new.c	2020-12-22 00:46:06.599251927 -0800
@@ -331,13 +331,13 @@
 		if (donumber) {
 			consumed = snprintf(intbuffer, intbuffersize, format,
 			    width, line);
-			(void)printf("%s",
-			    intbuffer + max(0, consumed - width));
+			(void)printf("%s%s",
+			    intbuffer + max(0, consumed - width), sep);
 			line += incr;
 		} else {
 			(void)printf("%*s", width, "");
 		}
-		(void)printf("%s%s", sep, buffer);
+		(void)printf("%s", buffer);
 
 		if (ferror(stdout))
 			err(EXIT_FAILURE, "output error");



Home | Main Index | Thread Index | Old Index