lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <fc3afc8e74ee9eda0b4eaff9a4d9ad32f1c461c4.camel@perches.com>
Date:   Fri, 28 May 2021 14:10:04 -0700
From:   Joe Perches <joe@...ches.com>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        Nathan Chancellor <nathan@...nel.org>,
        Arnd Bergmann <arnd@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Maxime Roussin-Bélanger 
        <maxime.roussinbelanger@...il.com>,
        Jean-Francois Dagenais <jeff.dagenais@...il.com>,
        Arnd Bergmann <arnd@...db.de>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Alexandru Ardelean <alexandru.ardelean@...log.com>,
        "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "clang-built-linux@...glegroups.com" 
        <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH] iio: si1133: fix format string warnings

On Fri, 2021-05-28 at 23:59 +0300, Andy Shevchenko wrote:
> On Thursday, May 27, 2021, Joe Perches <joe@...ches.com> wrote:
> > On Sun, 2021-05-16 at 10:36 +0100, Jonathan Cameron wrote:
> > > On Fri, 14 May 2021 10:45:02 -0700
> > > Nathan Chancellor <nathan@...nel.org> wrote:
> > > > On 5/14/2021 6:59 AM, Arnd Bergmann wrote:
> > > > > From: Arnd Bergmann <arnd@...db.de>
> > > > > 
> > > > > clang complains about multiple instances of printing an integer
> > > > > using the %hhx format string:
> > > > > 
> > > > > drivers/iio/light/si1133.c:982:4: error: format specifies type
> > 'unsigned char' but the argument has type 'unsigned int' [-Werror,-Wformat]
> > > > >                   part_id, rev_id, mfr_id);
> > > > >                   ^~~~~~~
> > > > > 
> > > > > Print them as a normal integer instead, leaving the "#02"
> > > > > length modifier.
> > []
> > > > > diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
> > []
> > > > > @@ -978,11 +978,11 @@ static int si1133_validate_ids(struct iio_dev
> > *iio_dev)
> > > > >                   return err;
> > > > > 
> > > > > 
> > > > >           dev_info(&iio_dev->dev,
> > > > > -          "Device ID part %#02hhx rev %#02hhx mfr %#02hhx\n",
> > > > > +          "Device ID part %#02x rev %#02x mfr %#02x\n",
> > > > >                    part_id, rev_id, mfr_id);
> > > > >           if (part_id != SI1133_PART_ID) {
> > > > >                   dev_err(&iio_dev->dev,
> > > > > -                 "Part ID mismatch got %#02hhx, expected %#02x\n",
> > > > > +                 "Part ID mismatch got %#02x, expected %#02x\n",
> > 
> > which is almost certainly wrong.
> > the length specification includes the # which is already 2 bytes.
> > 
> > Likely these should be 0x%02x
> 
> What’s the difference (except printing 0)?

(assuming the argument is unsigned char/u8)

%#02x will always emit more than the specified length (3 or 4 chars)
values < 16 are 0x<hexdigit>, values >= 16 are 0x<hexdigit><hexdigit>

0x%02x will always emit 4 chars

It's very likely the writer didn't know the difference and assumed
that the # did not count in the specified width.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ