LALSimFindAttachTime.c compile error with gcc-11
Building LALSuite with the newly released gcc-11.1 and I'm running into the following build error:
CC LALSimFindAttachTime.lo
LALSimFindAttachTime.c: In function 'XLALSimLocateOmegaTime':
LALSimFindAttachTime.c:94:33: error: '*ddradiusVec[1]' may be used uninitialized [-Werror=maybe-uninitialized]
94 | ddradiusVec[0] = ddradiusVec[1];
| ~~~~~~~~~~~^~~
LALSimFindAttachTime.c: In function 'XLALSimLocateAmplTime':
LALSimFindAttachTime.c:452:31: error: '*ddradiusVec[1]' may be used uninitialized [-Werror=maybe-uninitialized]
452 | ddradiusVec[0]=ddradiusVec[1];
| ~~~~~~~~~~~^~~
Looking at the code I see the following:
76 REAL8Vector timeHi;
77
78 timeHi.length = retLenHi;
79 timeHi.data = dynamicsHi->data;
80
81 double dt = timeHi.data[1] - timeHi.data[0];
82 double ddradiusVec[timeHi.length - 1];
83 unsigned int k;
84 for (k = 1; k < timeHi.length-1; k++) {
85 ddradiusVec[k] = (radiusVec->data[k+1] - 2.*radiusVec->data[k] + radiusVec->data[k-1])/dt/dt;
86 // XLAL_PRINT_INFO("%3.10f %3.10f\n", timeHi->data[k], ddradiusVec[k]);
87 }
88 // for (k = timeHi->length-3; k>=1; k--) {
89 // XLAL_PRINT_INFO("%3.10f %3.10f\n", timeHi->data[k], ddradiusVec[k]);
90 // if (ddradiusVec[k] < 0) {
91 // break;
92 // }
93 // }
94 ddradiusVec[0] = ddradiusVec[1];
and similar code for the second warning. Therefore I think that ddradiusVec[1]
is defined in this case it's just that the compiler can't guarantee it as the length of the timeHi
vector is calculated from retLenHi
which is coming in as a function argument and there is no checking on the length of this to ensure that timeHi.length-1
is at least 2 so that ddradiusVec[1]
is indeed defined.
Is there a minimum length for this argument and what checking is done to ensure that an appropriate length is being specified?