• amiga-fdisk: ftbfs with GCC-14

    From Christian T. Steigies@21:1/5 to All on Thu Aug 15 23:10:01 2024
    Hi,
    I need to fix this bug if we want to have amiga-fdisk in trixie: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1074807

    The attached patch fixes the error and removes one of the warnings, I assume that this is the correct solution?


    There are a couple more warnings which will probably become errors in one of the next gcc releases (We are at version 14? The last GCC version I
    remember using was something like 2.9, and I still have 2.6.3 on 10 floppy disks somewhere...). I am not sure how to get rid of those warnings.


    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 amigastuff.o amigastuff.c
    amigastuff.c: In function ‘rigiddisk_reorg’:
    amigastuff.c:859:20: warning: pointer targets in assignment from ‘LONG *’ {aka ‘long int *’} to ‘ULONG *’ {aka ‘long unsigned int *’} differ in signedness [-Wpointer-sign]
    859 | crk=&(FSHB(curr)->fhb_SegListBlocks);
    | ^
    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?

    --- a/fdisk.c
    +++ b/fdisk.c
    @@ -82,9 +82,9 @@

    /* 0x is hex, 0 is octal, everything else is decimal. */
    if (strncmp(s, "0x", 2) == 0 || strncmp(s, "0X", 2) == 0)
    - sscanf(s + 2, "%x", &n);
    + sscanf(s + 2, "%x", (unsigned int *) &n);
    else if (s[0] == '0' && s[1])
    - sscanf(s + 1, "%o", &n);
    + sscanf(s + 1, "%o", (unsigned int *) &n);
    else {
    d=s;
    while (d[0]!=0) {



    thanks,
    Christian

    --- a/amigastuff.c
    +++ b/amigastuff.c
    @@ -66,7 +66,7 @@

    int rigiddisk_new(int first);

    -char *get_block(block)
    +char *get_block(int block)
    {
    /* This is a true quickhack. Whenn we are in list only
    * mode, we may not have swap and so we may not be able
    @@ -81,9 +81,10 @@
    if (list_only)
    {
    if ((l=open(disk_device,O_RDONLY))<0) {
    - if (get_dev)
    + if (get_dev) {
    fprintf (stderr,"Cannot open device %s\n",disk_device);
    return NULL;
    + }
    }

    if (
  • From John Paul Adrian Glaubitz@21:1/5 to Christian T. Steigies on Thu Aug 15 23:50:01 2024
    Hi Christian,

    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 amigastuff.o amigastuff.c
    amigastuff.c: In function ‘rigiddisk_reorg’:
    amigastuff.c:859:20: warning: pointer targets in assignment from ‘LONG *’ {aka ‘long int *’} to ‘ULONG *’ {aka ‘long unsigned int *’} differ in signedness [-Wpointer-sign]
    859 | crk=&(FSHB(curr)->fhb_SegListBlocks);
    | ^

    In this case, you should just declare your variable such that it matches the function call.

    Switching between signed and unsigned without proper conversion is not a good idea in general.

    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:

    https://en.cppreference.com/w/c/io/fprintf https://www.ibm.com/docs/en/zos/2.4.0?topic=files-inttypesh-io-format-integer-types

    I fixed similar bugs in powerpc-utils in the past, see:

    https://github.com/ibm-power-utilities/powerpc-utils/commit/b46743ca68b6a06a2c82de4048d94d3d5191717f

    It can be a bit tricky to find the proper format specifier. When testing the change,
    make sure to test build on both 32- and 64-bit systems as well as little- and big-
    endian.

    I would recommend to test on powerpc and ppc64 (perotto.debian.net) and barriere.debian.org
    (i386 and amd64).

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geert Uytterhoeven@21:1/5 to glaubitz@physik.fu-berlin.de on Sun Aug 18 11:20:01 2024
    Hi Adrian,

    On Thu, Aug 15, 2024 at 11:44 PM John Paul Adrian Glaubitz <glaubitz@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 -- geert@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to Geert Uytterhoeven on Sun Aug 18 11:40:01 2024
    Hi,

    On Sun, 2024-08-18 at 11:19 +0200, Geert Uytterhoeven wrote:
    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").

    OK, so if the numbers are never supposed to be negative, then the variables should
    be declared as unsigned in the first place. I would avoid casting the types as this can often cause other problems.

    Adrian

    --
    .''`. John Paul Adrian Glaubitz
    : :' : Debian Developer
    `. `' Physicist
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)