If jot is run without arguments, prec will never be changed from -1.
This results in the nonsensical format string "%.-1f" being produced in
getformat(). __vfprintf() will misinterpret the - as a left adjustment
flag and the precision used will be 0. The result is the samw as "%.0f",
which is what we want.
The second tweak is to use de Morgan's rule to get rid of an unnecessary
if scope that sets use_unif to its initialized value.
Index: jot.c
===================================================================
RCS file: /cvs/src/usr.bin/jot/jot.c,v
retrieving revision 1.51
diff -u -p -r1.51 jot.c
--- jot.c 30 Jul 2021 02:47:37 -0000 1.51
+++ jot.c 12 Aug 2021 22:03:47 -0000
@@ -160,10 +160,10 @@ main(int argc, char *argv[])
mask |= REPS;
if (reps == 0)
infinity = true;
- if (prec == -1)
- prec = 0;
}
case 0:
+ if (prec == -1)
+ prec = 0;
break;
default:
errx(1, "Too many arguments. What do you mean by %s?",
@@ -258,9 +258,7 @@ main(int argc, char *argv[])
}
x = ender - begin;
- if (prec == 0 && (fmod(ender, 1) != 0 || fmod(begin, 1) != 0))
- use_unif = 0;
- else {
+ if (prec > 0 || (fmod(ender, 1) == 0 && fmod(begin, 1) == 0)) {
double range;
while (prec-- > 0)