nasa / bplib

Apache License 2.0
30 stars 13 forks source link

Cast-align warnings in latest compiler version (gcc 12) #229

Closed jphickey closed 1 year ago

jphickey commented 1 year ago

Describe the bug When compiling with GCC version 12.2, along with the -Wcast-align=strict option, some cast alignment warnings appear.

For example:

/home/joe/code/cfecfs/github/libs/bplib/mpool/src/v7_mpool.c: In function ‘bplib_mpool_get_block_content’:
/home/joe/code/cfecfs/github/libs/bplib/mpool/src/v7_mpool.c:169:16: error: cast increases required alignment of target type [-Werror=cast-align]
  169 |         return (bplib_mpool_block_content_t *)cb;
      |                ^

To Reproduce Build with GCC 12.x and use -Wcast-align=strict compiler option.

Expected behavior Should build clean.

System observed on: Anything with latest GCC and/or strict alignment requirements.

Additional context These are all pointer arithmetic operations, generally from taking a base pointer and adding the offset to an internal object within. They are safe because the pointer address offset being used in the calculation was originally derived using offsetof() with the correct struct definition, so this will be correctly aligned.

In general the warning can be squelched by passing it through the void* type.

Reporter Info Joseph Hickey, Vantage Systems, Inc.