On Sun, Dec 10, 2017 at 03:49:21PM +0100, Theo Buehler wrote:
> On Sun, Dec 10, 2017 at 03:29:51PM +0100, Theo Buehler wrote:
> > The printf(3) manual says that DOU are deprecated but are supposed to
> > behave the same way as ld, lo and lu.
>
> I forgot to say that I found this while looking into the code coverage
> report by Sergey Bronnikov and found that these format strings aren't
> covered by our tests.
>
> One small comment below.
>
> > However:
> > $ jot -w '%ld' 5 -2
> > -2
> > -1
> > 0
> > 1
> > 2
> > $ jot -w '%D' 5 -2
> > 4294967294
> > 4294967295
> > 0
> > 1
> > 2
> > $ jot -w '%ld' 4 4294967294
> > 4294967294
> > 4294967295
> > 4294967296
> > 4294967297
> > $ jot -w '%D' 4 4294967294
> > jot: range error in conversion: 4294967294.000000
> >
> > Similarly for %O and %U.
> >
> > This makes %{D,O,U} synonymous with %l{d,o,u}:
Any takers?
Note that this change affects the cast in putdata() only. The double x
is cast with (unsigned long) for %O and %U and with (long) for %D
instead of (unsigned int) or (int), respectively. After setting
longdata, setting intdata to true is a no-op, but it matches exactly
what %ld, %lo and %lu do, so I kept it.
Index: usr.bin/jot/jot.c
===================================================================
RCS file: /var/cvs/src/usr.bin/jot/jot.c,v
retrieving revision 1.36
diff -u -p -r1.36 jot.c
--- usr.bin/jot/jot.c 2 Sep 2016 14:23:09 -0000 1.36
+++ usr.bin/jot/jot.c 11 Dec 2017 01:49:55 -0000
@@ -420,12 +420,16 @@ getformat(void)
intdata = true;
break;
case 'D':
+ /* %lD is undefined */
if (!longdata) {
+ longdata = true; /* %D behaves as %ld */
intdata = true;
break;
}
case 'O': case 'U':
+ /* %lO and %lU are undefined */
if (!longdata) {
+ longdata = true; /* %O, %U behave as %lo, %lu */
intdata = nosign = true;
break;
}