ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
675 stars 273 forks source link

runtime error: member access within misaligned address for type 'struct CMOCK_x_CALL_INSTANCE' #178

Open Xunnamius opened 6 years ago

Xunnamius commented 6 years ago

First off, let me say THANK YOU for this fantastic suite of tools. You guys have made my life categorically easier with your efforts.

Anyhoo, I've been encountering a small almost-issue for a year or two now with some of my mocks. See the attached picture below. It happens no matter which memory mode I have defined (static vs dynamic). Also, it doesn't care what I define CMOCK_MEM_ALIGN to be (I've tried 2 and 3). The error doesn't seem to affect the results of my tests, however.

Note: I'm also using Unity and CException

2018-07-12 1

The expected behavior here would be these error messages not appearing. I suspect it's ultimately a non-issue or perhaps some small misconfiguration, but I thought I'd report it anyway.

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.10' --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.10)

uname -a:

Linux XUNNMORTY 4.14.47-132 #1 SMP PREEMPT Sun Jun 3 22:33:16 UTC 2018 armv7l armv7l armv7l GNU/Linux

The small MWE I came up with isn't sufficient to reproduce the behavior, but if you'd like I can come up with an example that should (at least on my system).

mvandervoord commented 6 years ago

If you don't mind, can you post a copy of the struct that is getting produce in the mock complained about? I'd like to see what its contents look like.

The alignment options effect the way data is stuffed into the data queue as CMock runs, but I'd not considered that we might have to force padding on the structs themselves (I honestly thought the compiler would always handle that for us). Clearly there are situations where that is not true, though. I'd like to see what that looks like. :)

Xunnamius commented 6 years ago

@mvandervoord It's these two structs:

typedef struct _CMOCK_blfs_backstore_read_CALL_INSTANCE
{
  UNITY_LINE_TYPE LineNumber;
  CMOCK_ARG_MODE IgnoreMode;
  blfs_backstore_t* Expected_backstore;
  uint8_t* Expected_buffer;
  uint32_t Expected_length;
  uint64_t Expected_offset;
  CEXCEPTION_T ExceptionToThrow;
  int Expected_backstore_Depth;
  int Expected_buffer_Depth;
  int ReturnThruPtr_backstore_Used;
  blfs_backstore_t* ReturnThruPtr_backstore_Val;
  int ReturnThruPtr_backstore_Size;
  int ReturnThruPtr_buffer_Used;
  uint8_t* ReturnThruPtr_buffer_Val;
  int ReturnThruPtr_buffer_Size;
  int IgnoreArg_backstore;
  int IgnoreArg_buffer;
  int IgnoreArg_length;
  int IgnoreArg_offset;

} CMOCK_blfs_backstore_read_CALL_INSTANCE;
typedef struct _CMOCK_blfs_backstore_write_body_CALL_INSTANCE
{
  UNITY_LINE_TYPE LineNumber;
  CMOCK_ARG_MODE IgnoreMode;
  blfs_backstore_t* Expected_backstore;
  uint8_t* Expected_buffer;
  uint32_t Expected_length;
  uint64_t Expected_offset;
  CEXCEPTION_T ExceptionToThrow;
  int Expected_backstore_Depth;
  int Expected_buffer_Depth;
  int ReturnThruPtr_backstore_Used;
  blfs_backstore_t* ReturnThruPtr_backstore_Val;
  int ReturnThruPtr_backstore_Size;
  int IgnoreArg_backstore;
  int IgnoreArg_buffer;
  int IgnoreArg_length;
  int IgnoreArg_offset;

} CMOCK_blfs_backstore_write_body_CALL_INSTANCE;

For these two function headers:

void blfs_backstore_read_body(blfs_backstore_t * backstore, uint8_t * buffer, uint32_t length, uint64_t offset);

void blfs_backstore_write_body(blfs_backstore_t * backstore, const uint8_t * buffer, uint32_t length, uint64_t offset);