Re: [PATCH v2 2/4] lib: test_scanf: Add tests for sscanf number conversion

From: Petr Mladek
Date: Wed Dec 16 2020 - 10:00:58 EST


On Tue 2020-12-15 14:26:53, Richard Fitzgerald wrote:
>
>
> On 09/12/2020 14:15, Petr Mladek wrote:
> > On Mon 2020-11-30 14:57:58, Richard Fitzgerald wrote:
> > > Adds test_sscanf to test various number conversion cases, as
> > > number conversion was previously broken.
> > >
> > > This also tests the simple_strtoxxx() functions exported from
> > > vsprintf.c.
> >
> > It is impressive.
> >
> > Honestly, I do not feel to be expert on testing and mathematics.
> > I am not sure how comprehensive the test is. Also I am not
> > sure what experts would say about the tricks with random
> > numbers.
> >
> > Anyway, this is much more than what I have expected. And it checks
> > great number of variants and corner cases.
> >
> > I suggest only one small change, see below.
> >
> > > --- /dev/null
> > > +++ b/lib/test_scanf.c
> > > +#define test_one_number(T, gen_fmt, scan_fmt, val, fn) \
> > > +do { \
> > > + const T expect_val = (T)(val); \
> > > + T result = ~expect_val; /* should be overwritten */ \
> >
> > If I get it correctly, this is supposed to initialize the temporary
> > variable with a value that is different from the expected value.
> > It will cause test failure when it is not updated by vsscanf().
> >
> > It does not work for zero value. A better solution might be to add
>
> That's a ~, not a -
> ~0 = 0xFFFFFFFF
> ~-1 = 0

I see. This works well.

I am sorry for the noise. Sigh, I think that I need stronger glasses
or use a monitor. I am not able to distinguish the two characeters
without staring closely on the laptop screen. I wish I was able to
work from the office again.

Best Regards,
Petr