lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 15 Dec 2014 18:32:18 +0900
From:	Masahiro Yamada <yamada.m@...panasonic.com>
To:	linux-kernel@...r.kernel.org
Cc:	Randy Dunlap <rdunlap@...radead.org>,
	Andrew Murray <amurray@...-data.co.uk>,
	linux-m68k@...ts.linux-m68k.org
Subject: [Question] How to print size_t type variable?

Hi experts,

I read through Documentation/printk-formats.txt

It clearly says to use "%zu" or "%zx" to print size_t variables,
but I still have a question.


Assume we have code something like:

    printk("%zx", (size_t)10);


I think this code works fine as long as it includes
the compiler-provided <stddef.h>.

In the kernel space, however, <stddef.h> is never included.
Instead, size_t is defined by include/linux/types.h
and include/uapi/asm-generic/posix_types.h.


That is, size_t is defined independently from the compiler you are using,
although the compiler still decides which variable type is expected for the "%zx" format.
 
This causes compiler warnings for some compilers.

On bare-metal m68k toolchains, for example, size_t is "unsignd long",
whearas it is "unsigned int" on kernel.org m68k toolchains.


I see such warnings when I built the kernel with bare-metal m68k toolchains.


$ git describe 
v3.18
$ make ARCH=m68k  CROSS_COMPILE=m68k-elf-  defconfig all
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
*** Default configuration is based on 'multi_defconfig'
kernel/time/Kconfig:163:warning: range is invalid
#
# configuration written to .config
#

  [ snip ]

  LD      init/mounts.o
  CC      init/initramfs.o
init/initramfs.c: In function 'populate_rootfs':
init/initramfs.c:635:5: warning: format '%zd' expects argument of type 'signed size_t', but argument 2 has type 'ssize_t' [-Wformat]




Any advice?
How to fix this issue?




Best Regards
Masahiro Yamada

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ