With gcc 8.3.1 I am getting warnings in asyn that I don’t get with older versions of gcc (e.g. 4.8.5).
[epics@viper asyn]$ make -s
In function ‘setEnums.constprop’,
inlined from ‘interruptCallbackEnumBi’ at ../../asyn/devEpics/devAsynInt32.c:759:5:
../../asyn/devEpics/devAsynInt32.c:444:25: warning: ‘strncpy’ forming offset [27, 51] is out of the bounds [0, 26] [-Warray-bounds]
if (outStrings) strncpy(&outStrings[i*MAX_ENUM_STRING_SIZE], inStrings[i], MAX_ENUM_STRING_SIZE-1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘setEnums.constprop’,
inlined from ‘interruptCallbackEnumBo’ at ../../asyn/devEpics/devAsynInt32.c:773:5:
../../asyn/devEpics/devAsynInt32.c:444:25: warning: ‘strncpy’ forming offset [27, 51] is out of the bounds [0, 26] [-Warray-bounds]
if (outStrings) strncpy(&outStrings[i*MAX_ENUM_STRING_SIZE], inStrings[i], MAX_ENUM_STRING_SIZE-1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These warnings are when writing enum strings to the ONST, TWST, … fields of bo, bi, mbbo, and mbbi records. The function is passed the address of the ZRST field, and computes the addresses of the other fields based on the knowledge of
how large each field is (26 bytes) and that the fields are consecutive. The compiler now is smart enough to say that the array I passed is actually only 26 bytes and so complains about writing to the other fields.
Is there a way to fix this via a cast to avoid that warning?
Mark