[PATCH 3/3] printk: Use %zu to format size_t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When compiling for 32-bit:

    util_lib/elf_info.c: In function ‘dump_dmesg_lockless’:
    util_lib/elf_info.c:1095:39: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=]
     1095 |   fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
	  |                                     ~~^
	  |                                       |
	  |                                       long unsigned int
	  |                                     %u
     1096 |    printk_ringbuffer_sz, strerror(errno));
	  |    ~~~~~~~~~~~~~~~~~~~~
	  |    |
	  |    size_t {aka unsigned int}
    util_lib/elf_info.c:1101:49: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=]
     1101 |   fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
	  |                                               ~~^
	  |                                                 |
	  |                                                 long unsigned int
	  |                                               %u
     1102 |    printk_ringbuffer_sz, strerror(errno));
	  |    ~~~~~~~~~~~~~~~~~~~~
	  |    |
	  |    size_t {aka unsigned int}

Indeed, "size_t" is "unsigned int" on 32-bit platforms, and "unsigned
long" on 64-bit platforms.

Fix this by formatting using "%zu".

Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
Signed-off-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
---
 util_lib/elf_info.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 7c0a2c345379a7ca..676926ca8c5f3766 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -1092,13 +1092,13 @@ static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))
 	kaddr = read_file_pointer(fd, vaddr_to_offset(prb_vaddr));
 	m.prb = calloc(1, printk_ringbuffer_sz);
 	if (!m.prb) {
-		fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
+		fprintf(stderr, "Failed to malloc %zu bytes for prb: %s\n",
 			printk_ringbuffer_sz, strerror(errno));
 		exit(64);
 	}
 	ret = pread(fd, m.prb, printk_ringbuffer_sz, vaddr_to_offset(kaddr));
 	if (ret != printk_ringbuffer_sz) {
-		fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
+		fprintf(stderr, "Failed to read prb of size %zu bytes: %s\n",
 			printk_ringbuffer_sz, strerror(errno));
 		exit(65);
 	}
-- 
2.25.1


_______________________________________________
kexec mailing list
kexec@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/kexec




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux