Hi Adrian,

On Thu, Aug 15, 2024 at 11:44 PM John Paul Adrian Glaubitz
<glaub...@physik.fu-berlin.de> wrote:
> On Thu, 2024-08-15 at 22:56 +0200, Christian T. Steigies wrote:
> > gcc -g -O2 -Werror=implicit-function-declaration 
> > -ffile-prefix-map=/home/cts/salsa/amiga-fdisk=. -fstack-protector-strong 
> > -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection 
> > -Wall -pedantic -DUSE_READLINE=yes -I./include -Wdate-time 
> > -D_FORTIFY_SOURCE=2  -c -o fdisk.o fdisk.c
> > fdisk.c: In function ‘atonum’:
> > fdisk.c:85:33: warning: format ‘%x’ expects argument of type ‘unsigned int 
> > *’, but argument 3 has type ‘int *’ [-Wformat=]
> >    85 |                 sscanf(s + 2, "%x", &n);
> >       |                                ~^   ~~
> >       |                                 |   |
> >       |                                 |   int *
> >       |                                 unsigned int *
> >       |                                %x
> > fdisk.c:87:33: warning: format ‘%o’ expects argument of type ‘unsigned int 
> > *’, but argument 3 has type ‘int *’ [-Wformat=]
> >    87 |                 sscanf(s + 1, "%o", &n);
> >       |                                ~^   ~~
> >       |                                 |   |
> >       |                                 |   int *
> >       |                                 unsigned int *
> >       |                                %o
> >
> > I tried defining n in fdisk.c as unsigned int but this caused even more
> > warnings in other places.  Do I have to cast the arguments in sscanf to
> > unsigned int?  It wants "unsigned int *", is it as simple as this or is
> > there a better solution?
>
> In this case, I would just recommend to use the proper format specifiers, see:

"%x" and "%o" always operate on unsigned values.  There are no
format specifiers for signed hexadecimal and octal values, unlike for
decimal values ("%u" vs. "%d").

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Reply via email to