Concerning the commit commit 8970a4793c302c0bb8619a5dde56c8ca8de20532 Author: Kevin McCarthy <ke...@8t8.us> Date: 2021-07-21 22:26:25 +0200
Silence strfcpy() warning in dotlock_deference_symlink(). The compiler is being a bit strange, only picking out and warning about the 'strfcpy (d, pathptr, l);' line at the bottom of the function, even though the source and dest are the same size. It seems a shame to leave just this last one, since all the other warnings (at least on Debian) have been vanquished. So, to calm the compiler down, "russian doll" the buffer size down the call stack "dotlock_dispatch() -> dotlock_prepare() -> dotlock_deference_symlink()". I actually think that the compiler should warn in every case, but isn't able to detect all potential issues. The strfcpy definition seems wrong: # define strfcpy(A,B,C) strncpy (A,B,C), *(A+(C)-1)=0 If A and B are buffers of size C, the strncpy call will yield a non-null terminated destination at this point, hence a potential warning (see the gcc(1) man page). Note the *(A+(C)-1)=0. This means that A[(C)-1] will be set to 0. Thus you want to fill A[0] to A[(C)-2], i.e. copy (C)-1 bytes. So the definition should be # define strfcpy(A,B,C) strncpy (A,B,(C)-1), *((A)+(C)-1)=0 Now, this doesn't solve the warnings, and I suppose that there is a bug in GCC. There are actually many issues: https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=stringop-truncation I would say that it is better to silence the warning with -Wno-stringop-truncation rather than trying to avoid it in the code. -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)