rt-net / RaspberryPiMouse

Raspberry Pi Mouse Device Driver
Other
60 stars 455 forks source link

size_t型の変数のフォーマットに関してビルド時に警告が出る #37

Closed Tiryoh closed 4 years ago

Tiryoh commented 4 years ago

Describe the bug

rtmouse.cをビルドするとフォーマットに関して以下の警告が出ている

format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t {aka long unsigned int}’

size_t型の変数のフォーマットは%zdに統一することが望ましい

Full log

$ make
make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=0 modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-1052-raspi2'
  CC [M]  /home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.o
In file included from ./include/linux/printk.h:7:0,
                 from ./include/linux/kernel.h:14,
                 from ./include/linux/list.h:9,
                 from ./include/linux/kobject.h:20,
                 from ./include/linux/cdev.h:5,
                 from /home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:25:
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c: In function ‘sw_read’:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
./include/linux/kern_levels.h:14:19: note: in expansion of macro ‘KERN_SOH’
 #define KERN_INFO KERN_SOH "6" /* informational */
                   ^~~~~~~~
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:586:10: note: in expansion of macro ‘KERN_INFO’
   printk(KERN_INFO "err sample_char_read size(%d)\n", count);
          ^~~~~~~~~
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:586:48: note: format string is defined here
   printk(KERN_INFO "err sample_char_read size(%d)\n", count);
                                               ~^
                                               %ld
In file included from ./include/linux/printk.h:7:0,
                 from ./include/linux/kernel.h:14,
                 from ./include/linux/list.h:9,
                 from ./include/linux/kobject.h:20,
                 from ./include/linux/cdev.h:5,
                 from /home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:25:
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c: In function ‘sensor_read’:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
./include/linux/kern_levels.h:14:19: note: in expansion of macro ‘KERN_SOH’
 #define KERN_INFO KERN_SOH "6" /* informational */
                   ^~~~~~~~
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:657:10: note: in expansion of macro ‘KERN_INFO’
   printk(KERN_INFO "err sample_char_read size(%d)\n", count);
          ^~~~~~~~~
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:657:48: note: format string is defined here
   printk(KERN_INFO "err sample_char_read size(%d)\n", count);
                                               ~^
                                               %ld
In file included from ./include/linux/printk.h:7:0,
                 from ./include/linux/kernel.h:14,
                 from ./include/linux/list.h:9,
                 from ./include/linux/kobject.h:20,
                 from ./include/linux/cdev.h:5,
                 from /home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:25:
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c: In function ‘rtcnt_read’:
./include/linux/kern_levels.h:5:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
 #define KERN_SOH "\001"  /* ASCII Start Of Header */
                  ^
./include/linux/kern_levels.h:14:19: note: in expansion of macro ‘KERN_SOH’
 #define KERN_INFO KERN_SOH "6" /* informational */
                   ^~~~~~~~
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:1188:10: note: in expansion of macro ‘KERN_INFO’
   printk(KERN_INFO "err sample_char_read size(%d)\n", count);
          ^~~~~~~~~
/home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.c:1188:48: note: format string is defined here
   printk(KERN_INFO "err sample_char_read size(%d)\n", count);
                                               ~^
                                               %ld
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.mod.o
  LD [M]  /home/ubuntu/RaspberryPiMouse/src/drivers/rtmouse.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-1052-raspi2'