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?
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
https://github.com/ibm-power-utilities/powerpc-utils/commit/b46743ca68b6a06a2c82de4048d94d3d5191717f
On Thu, 2024-08-15 at 22:56 +0200, Christian T. Steigies wrote:time -D_FORTIFY_SOURCE=2 -c -o fdisk.o fdisk.c
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-
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:
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").
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 487 |
Nodes: | 16 (2 / 14) |
Uptime: | 02:05:55 |
Calls: | 9,662 |
Calls today: | 4 |
Files: | 13,709 |
Messages: | 6,166,608 |
Posted today: | 2 |