On Mon, Jul 25, 2016 at 01:26:51PM -0500, attila wrote:
> Hi tech@,
>
> After the recent discussion on jot I noticed there were no tests for
> it. I looked around and saw that FreeBSD had what looked like decent
> jot tests, so I brought them into my tree. They appear to have
> discovered a couple of bugs and I'd like some help in sorting it out.
> The current state of the suite in my tree is the first patch attached
> to this email.
Thanks. I fear that it is too late for fixing this for the release.
Instead of rushing something in that fixes a potential minor bug that
was present for at least a decade, I'd rather wait for unlock and think
about it and test it properly.
That said, while the behavior resulting from your patch makes sense to
me, I'm not entirely convinced that it and some of the failing
regression tests match the behavior documented in the manual:
The last four arguments indicate, respectively, the maximum number of
data, the lower bound, the upper bound, and the step size. While at
least one of them must appear, any of the other three may be omitted, and
will be considered as such if given as ‘-’. Any three of these arguments
determines the fourth. If four are specified and the given and computed
values of reps conflict, the lower value is used. If fewer than three
are specified, defaults are assigned left to right, except for s, which
assumes its default unless both begin and end are given.
Defaults for the four arguments are, respectively, 100, 1, 100, and 1.
reps is expected to be an unsigned integer, and if given as zero is taken
to be infinite. begin and end may be given as real numbers or as
characters representing the corresponding value in ASCII. The last
argument must be a real number.
The way I understand this is that "jot - - - -" would indicate four
omitted arguments in conflict with "at least one of them must appear",
so maybe bailing out would be better than assuming the defaults...
Similarly, the expected output of the failing dhhd and dhhd2 tests
consists of 101 and 141 lines, which is in conflict with the documented
default value of 100 for reps if it was omitted (although the tests have
much saner output than what we currently have).
The ascii test is successful if I grab the file regress.ascii.out from
https://svnweb.freebsd.org/base/head/usr.bin/jot/tests/regress.ascii.out?view=log
(since it contains binary data, -ko is needed for cvs) and the failure
of wdl and wxn seems to be a bug in the regression test suite (creating
empty files, the tests fail, despite the fact that no output is
generated by the tested commands).
The failure of the remaining wp3, wp4, wp5 is fixed by the following
simple patch (which was part of pjanzen's -r1.8 in OpenBSD but was lost
in -r1.17):
If '%%' appears in the format string, it must be skipped properly,
otherwise the second '%' is interpreted as the start of a format string.
Index: jot.c
===================================================================
RCS file: /var/cvs/src/usr.bin/jot/jot.c,v
retrieving revision 1.28
diff -u -p -r1.28 jot.c
--- jot.c 17 Jul 2016 04:04:46 -0000 1.28
+++ jot.c 25 Jul 2016 19:42:44 -0000
@@ -394,8 +394,11 @@ getformat(void)
if (boring) /* no need to bother */
return;
for (p = format; *p != '\0'; p++) /* look for '%' */
- if (*p == '%' && *(p+1) != '%') /* leave %% alone */
- break;
+ if (*p == '%') {
+ if (*(p + 1) != '%')
+ break;
+ p++; /* leave %% alone */
+ }
sz = sizeof(format) - strlen(format) - 1;
if (*p == '\0' && !chardata) {
int n;