2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 <2020> 2021 2022 2023 2024 | Index | 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 <2020> 2021 2022 2023 2024 |
<== Date ==> | <== Thread ==> |
---|
Subject: | Compiler warning question |
From: | Mark Rivers via Core-talk <core-talk at aps.anl.gov> |
To: | EPICS core-talk <core-talk at aps.anl.gov> |
Date: | Tue, 15 Sep 2020 22:30:27 +0000 |
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 |