Error building lalapps pulsar in conda platform test
The new conda platform test has exposed an error building lalapps
:
make[8]: Entering directory '/builds/duncanmmacleod/lalsuite/lalapps/src/pulsar/Hough'
CC HoughValidate.o
CC PeakSelect.o
CC DriveHoughMulti.o
CC FstatToplist.o
In file included from /opt/conda/envs/lalsuite-platform-tests/x86_64-conda-linux-gnu/sysroot/usr/include/string.h:642,
from /builds/duncanmmacleod/lalsuite/lal/include/lal/LALStatusMacros.h:33,
from /builds/duncanmmacleod/lalsuite/lal/include/lal/LALStdlib.h:58,
from /builds/duncanmmacleod/lalsuite/lal/include/lal/StringInput.h:23,
from FstatToplist.c:27:
In function 'strncpy',
inlined from 'write_hs_checkpoint' at FstatToplist.c:744:3:
/opt/conda/envs/lalsuite-platform-tests/x86_64-conda-linux-gnu/sysroot/usr/include/bits/string3.h:121:10: error: '__builtin_strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
121 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FstatToplist.c: In function 'write_hs_checkpoint':
FstatToplist.c:738:9: note: length computed here
738 | len = strlen(filename)+strlen(TMP_EXT)+1;
| ^~~~~~~~~~~~~~~~
CC HeapToplist.o
cc1: all warnings being treated as errors
CC MCInjectHoughMulti.o
make[8]: *** [Makefile:912: FstatToplist.o] Error 1
make[8]: *** Waiting for unfinished jobs....
make[8]: Leaving directory '/builds/duncanmmacleod/lalsuite/lalapps/src/pulsar/Hough'
I think this relates to the combined use of len = strlen(filename)
and then strncpy(tmpfilename, filename, len)
- there's an interesting discussion on this thread about that and whether this is a bug in gcc.
It might be a solution to just use strcpy
/strcat
instead of strncpy
/strncat
, but I'm not a C expert:
diff --git a/lalapps/src/pulsar/Hough/FstatToplist.c b/lalapps/src/pulsar/Hough/FstatToplist.c
index 6d9a920d1d..2ec4ef8d56 100644
--- a/lalapps/src/pulsar/Hough/FstatToplist.c
+++ b/lalapps/src/pulsar/Hough/FstatToplist.c
@@ -741,8 +741,8 @@ int write_hs_checkpoint(const char*filename, toplist_t*tl, UINT4 counter, BOOLEA
LogPrintf(LOG_CRITICAL,"Couldn't allocate tmpfilename\n");
return(-2);
}
- strncpy(tmpfilename,filename,len);
- strncat(tmpfilename,TMP_EXT,len);
+ strcpy(tmpfilename,filename);
+ strcat(tmpfilename,TMP_EXT);
/* calculate checksum */
checksum = 0;