tpm2-software / tpm2-tools

The source repository for the Trusted Platform Module (TPM2.0) tools
https://tpm2-software.github.io
718 stars 378 forks source link

GCC 5.4.0 complains "-Werror=int-to-pointer-cast" on "test_tpm2_session.c" #752

Closed liuqun closed 6 years ago

liuqun commented 6 years ago

tpm2-tools branch master commit 3ab33f7 When configured with cmocka unit test enabled, GCC 5.4.0 complains about casting from integer to pointer (intergers and pointers might have different sizes in arm-linux-gnueabihf-gcc) :

  CC       test/unit/test_unit_test_tpm2_session-test_tpm2_session.o
test/unit/test_tpm2_session.c: In function ‘__wrap_Tss2_Sys_StartAuthSession’:
test/unit/test_tpm2_session.c:116:24: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     expected_data *e = (expected_data *) mock();
                        ^
cc1: all warnings being treated as errors

GCC on Raspberry Pi 3 (target: arm-linux-gnueabihf)

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/5/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.5' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.5) 
$ ls -l `which arm-linux-gnueabihf-gcc`
lrwxrwxrwx 1 root root 5 Feb 11  2016 /usr/bin/arm-linux-gnueabihf-gcc -> gcc-5
$ ls -l `which gcc`
lrwxrwxrwx 1 root root 5 Feb 11  2016 /usr/bin/gcc -> gcc-5
# cd tpm2-tools && ./bootstrap && ./configure --enable-unit

CC=arm-linux-gnueabihf-gcc
CFLAGS='-Wall -Wextra -Werror=int-to-pointer-cast'
arm-linux-gnueabihf-gcc $CFLAGS -c test/unit/test_tpm2_session.c  -I lib  -I /usr/local/include/

test/unit/test_tpm2_session.c: In function ‘__wrap_Tss2_Sys_StartAuthSession’:
test/unit/test_tpm2_session.c:116:24: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     expected_data *e = (expected_data *) mock();
                        ^
cc1: some warnings being treated as errors

This also happened in tpm2-tss/abrmd, and has been solved by flihp with PR https://github.com/intel/tpm2-abrmd/pull/241, see issue https://github.com/intel/tpm2-abrmd/issues/239

Replace

e = (expected_data *) mock();

with

e = mock_type(expected_data *);

would fix GCC warnings.

williamcroberts commented 6 years ago

Ahh thanks for the fix as well. Will queue this up. If you need it done faster, patches are always welcome.

williamcroberts commented 6 years ago

I have a fix for this on 45e8df00