Skip to contentSkip to conversation

Use 'long long' for printf() format string and ELF64 numbers.

PATCH In review Bernhard Walle 3 participants 4 messages May 25, 2008 – May 28, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use 'long long' for printf() format string and ELF64 numbers.

Since 'long long' is 64 bit wide on almost any platform, especially on 32 bit platforms (like i386) while 'long long' is only 64 bit on 64 bit platforms but 32 bit on 32 bit platforms, 'long long' is more suited and fixes compiler warnings like

kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 4 has type 'Elf64_Off'
kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 5 has type 'Elf64_Addr'
...
kexec/crashdump-elf.c:248: warning: format '%lx' expects type \
'long unsigned int', but argument 8 has type 'Elf64_Xword'

Tested on i686-pc-linux-gnu.

kexec/crashdump-elf.c +6 -6
index 7d2befe..f01accb 100644
@@ -4,12 +4,12 @@
 #endif
 
 #if (ELF_WIDTH == 64)
-#define dbgprintf_phdr(prefix, phdr)					\
-do {									\
-	dbgprintf("%s: p_type = %u, p_offset = 0x%lx p_paddr = 0x%lx "	\
-		"p_vaddr = 0x%lx p_filesz = 0x%lx p_memsz = 0x%lx\n",	\
-		(prefix), (phdr)->p_type, (phdr)->p_offset, (phdr)->p_paddr, \
-		(phdr)->p_vaddr, (phdr)->p_filesz, (phdr)->p_memsz);	\
+#define dbgprintf_phdr(prefix, phdr)						\
+do {										\
+	dbgprintf("%s: p_type = %u, p_offset = 0x%llx p_paddr = 0x%llx "	\
+		"p_vaddr = 0x%llx p_filesz = 0x%llx p_memsz = 0x%llx\n",	\
+		(prefix), (phdr)->p_type, (phdr)->p_offset, (phdr)->p_paddr, 	\
+		(phdr)->p_vaddr, (phdr)->p_filesz, (phdr)->p_memsz);		\
 } while(0)
 #else
 #define dbgprintf_phdr(prefix, phdr)					\

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw
Quoted 13 lines · Bernhard Walle

Since 'long long' is 64 bit wide on almost any platform, especially on 32 bit platforms (like i386) while 'long long' is only 64 bit on 64 bit platforms but 32 bit on 32 bit platforms, 'long long' is more suited and fixes compiler warnings like

kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 4 has type 'Elf64_Off'
kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 5 has type 'Elf64_Addr'
...
kexec/crashdump-elf.c:248: warning: format '%lx' expects type \
'long unsigned int', but argument 8 has type 'Elf64_Xword'

Quoted 3 lines

Tested on i686-pc-linux-gnu.

Thanks Bernhard, I've had much less elegant ideas on how to solve that problem myself.

Signature · 7 lines
Horms


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#2 lore raw
In reply to Bernhard Walle
Quoted 2 lines · Bernhard Walle

kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 4 has type 'Elf64_Off'

This is what inttypes.h is for, right?

Quoted 1 line

dbgprintf("%s: p_type = %u, p_offset = 0x%llx p_paddr = 0x%llx " ...

Perhaps (... "p_offset = 0x" PRIx64 " p_paddr = 0x" PRIx64 ...)?

Jamey

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw
Quoted 10 lines · Jamey Sharp
Quoted 2 lines · Bernhard Walle

kexec/crashdump-elf.c:160: warning: format '%lx' expects type \
'long unsigned int', but argument 4 has type 'Elf64_Off'

This is what inttypes.h is for, right?

Quoted 1 line

dbgprintf("%s: p_type = %u, p_offset = 0x%llx p_paddr = 0x%llx " ...

Perhaps (... "p_offset = 0x" PRIx64 " p_paddr = 0x" PRIx64 ...)?

Yes, I know this, but it's really ugly to read IMO. If it's not really necessary I think it's better to avoid it.

Bernhard

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec