Skip to content

master branch uncompilable with up-to-date gcc

Description of problem

lalsimulation fails with

make[4]: Entering directory '/home/kipp/Development/lalsuite/lalsimulation/lib'
  CC       LALSimIMRNRWaveforms.lo
LALSimIMRNRWaveforms.c: In function ‘XLALSimIMRNRWaveformGetModes.constprop’:
LALSimIMRNRWaveforms.c:847:60: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  847 |       snprintf(phase_key, sizeof(phase_key), "phase_l%d_m%d", model, modem);
      |                                                            ^
LALSimIMRNRWaveforms.c:847:7: note: ‘snprintf’ output between 12 and 31 bytes into a destination of size 30
  847 |       snprintf(phase_key, sizeof(phase_key), "phase_l%d_m%d", model, modem);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

lalinspiral fails with

make[3]: Entering directory '/home/kipp/Development/lalsuite/lalinspiral/lib'
  CC       NRWaveInject.lo
NRWaveInject.c: In function ‘XLALFindNRFile’:
NRWaveInject.c:644:30: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘nrCatalog->data + (sizetype)((long unsigned int)k * 128)’ must not be NULL [-Werror=address]
  644 |     if ( nrCatalog->data + k == NULL ) {
      |                              ^~
cc1: all warnings being treated as errors

lalpulsar fails with

make[3]: Entering directory '/home/kipp/Development/lalsuite/lalpulsar/lib'
  CC       ConstructPLUT.lo
ConstructPLUT.c: In function ‘PLUTInitialize’:
ConstructPLUT.c:246:23: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘lut->bin + (sizetype)((long unsigned int)i * 16)’ must not be NULL [-Werror=address]
  246 |     if ( lut->bin + i == NULL ) {
      |                       ^~
ConstructPLUT.c:263:26: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘lut->border + (sizetype)((long unsigned int)i * 24)’ must not be NULL [-Werror=address]
  263 |     if ( lut->border + i == NULL ) {
      |                          ^~
cc1: all warnings being treated as errors

  CC       Peak2PHMD.lo
Peak2PHMD.c: In function ‘LALHOUGHPeak2PHMD’:
Peak2PHMD.c:250:37: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘lut->border + (sizetype)((long unsigned int)lb1 * 24)’ must not be NULL [-Werror=address]
  250 |             if (  lut->border + lb1 == NULL ) {
      |                                     ^~
Peak2PHMD.c:260:37: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘lut->border + (sizetype)((long unsigned int)lb2 * 24)’ must not be NULL [-Werror=address]
  260 |             if (  lut->border + lb2 == NULL ) {
      |                                     ^~
Peak2PHMD.c:269:37: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘lut->border + (sizetype)((long unsigned int)rb1 * 24)’ must not be NULL [-Werror=address]
  269 |             if (  lut->border + rb1 == NULL ) {
      |                                     ^~
Peak2PHMD.c:278:37: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘lut->border + (sizetype)((long unsigned int)rb2 * 24)’ must not be NULL [-Werror=address]
  278 |             if (  lut->border + rb2 == NULL ) {
      |                                     ^~
Peak2PHMD.c:288:39: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘phmd->firstColumn + (sizetype)j’ must not be NULL [-Werror=address]
  288 |             if (phmd->firstColumn + j == NULL) {
      |                                       ^~
Peak2PHMD.c:296:39: error: the comparison will always evaluate as ‘false’ for the pointer operand in ‘phmd->firstColumn + (sizetype)j’ must not be NULL [-Werror=address]
  296 |             if (phmd->firstColumn + j == NULL) {
      |                                       ^~
cc1: all warnings being treated as errors

Expected behavior

That it compile.

Steps to reproduce

$ make

Context/environment

gcc 12

Suggested solutions

In lalsimulation, as always, despite the text of the warning, gcc's complaint isn't so much that the target buffer is not necessarily large enough as that it is both not necessarily large enough and nothing is checking the return value of snprintf() to determine if the call failed. There are two ways to fix this: fix the buffer size so it's large enough for the message being generated, or add a check of the return value to silence the warning.

In lalinspiral the code is sufficiently nonsensical that I can't imagine what the author intended this to do to suggest a fix. The comment is "check catalog data is not null", so what is ->data? Why does adding an integer to it produce a pointer whose value should be checked at all, let alone in a loop? Does the loop change the pointer's value? Nothing about this makes sense.

In lalpulsar it looks like it's all the exact same error as in lalinspiral. Honestly, this is the weirdest thing. Whatever this is, it seems like lots of people believe this construct of adding an integer to a pointer and then testing to see if the result is NULL means something ... but I don't know what. It's inexplicable.

Edited by Kipp Cannon