NetBSD-Bugs archive

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

FWD: `-c` truncates range with `jot -r`



Forwarding this, as NetBSD is affected, too.


-- Elias

----- Forwarded message from Elias Pipping <elias%pipping.org@localhost> -----

From: Elias Pipping <elias%pipping.org@localhost>
Date: Sat, 23 Feb 2008 14:11:56 +0100
To: bugs%openbsd.org@localhost
Subject: `-c` truncates range with `jot -r`

I've come across what I believe to be a bug in jot(1).

The bug affects jot(1) on OpenBSD, NetBSD, and Mac OS X, but not
FreeBSD.

`jot -r 100000 97 98` is supposed to generate 100000 numbers in the
range from 97 to 98. That's what it does. Now `-c` is supposed to
convert those numbers to ASCII, but it also changes the range, which it
shouldn't. Without `-c`, the range is [97,98], with `-c` it's [a,b).
Here's a demo:

    % ./jot_obsd -r 100000 97 98 | sort -n | uniq -c 
    49983 97
    50017 98
    % ./jot_obsd -r -c 100000 97 98 | sort -n | uniq -c
    100000 a

and, for comparison:

    % ./jot_fbsd -r 100000 97 98 | sort -n | uniq -c  
    50018 97
    49982 98
    % ./jot_fbsd -r -c 100000 97 98 | sort -n | uniq -c
    50082 a
    49918 b

    % ./jot_nbsd -r 100000 97 98 | sort -n | uniq -c 
    49963 97
    50037 98
    % ./jot_nbsd -r -c 100000 97 98 | sort -n | uniq -c
    100000 a

    % ./jot_apple -r 100000 97 98 | sort -n | uniq -c  
    50028 97
    49972 98
    % ./jot_apple -r -c 100000 97 98 | sort -n | uniq -c
    100000 a


The tests were run on i386-apple-darwin9.2.0.
jot.c was retrieved from the following locations:

    
http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/usr.bin/jot/jot.c?rev=1.26.8.2
    
http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/jot/jot.c?rev=1.19
    
http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/usr.bin/jot/jot.c?rev=1.14.2.1
    http://www.opensource.apple.com/darwinsource/10.5.2/shell_cmds-118/jot/jot.c

And the following patches were applied (*only* to make jot compile!):

== snip ==
--- jot_fbsd.c
+++ jot_fbsd.c
@@ -43,7 +43,6 @@
 #endif
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.bin/jot/jot.c,v 1.26.8.2 2006/12/26 20:09:40 dds 
Exp $");
 
 /*
  * jot - print sequential or random data
--- jot_obsd.c
+++ jot_obsd.c
@@ -56,6 +56,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #define        REPS_DEF        100
 #define        BEGIN_DEF       1
@@ -124,7 +125,7 @@
                                errx(1, "-s word too long");
                        break;
                case 'p':
-                       prec = strtonum(optarg, 0, INT_MAX, &errstr);
+                       prec = atoi(optarg);
                        if (errstr != NULL)
                                errx(1, "bad precision value, %s: %s", errstr, 
                                        optarg);
== snip ==

gcc 4.0.1 (Apple Inc. build 5465) was used for compilation.



----- End forwarded message -----

Attachment: pgpuaYKib_2pf.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index