Skip to content
Prev 11106 / 12125 Next

[R-pkg-devel] truncating strings on purpose

Hi Ivan, List,

Thanks for the suggestion, and for the pointer on duplicating the error.
The good news is that I am able to trigger the warning locally now. The bad
news is that following the gcc docs on avoid the warning did not seem to
work:


gcc -std=gnu99 -fsanitize=undefined -fno-omit-frame-pointer -std=gnu11
-I"/usr/local/lib/R/include" -DNDEBUG   -I/usr/local/include
-fsanitize=address
-O2 -Wstringop-truncation -fPIC  -g -O2  -c input2.c -o input2.o

input2.c: In function ?inperrmsg?:

input2.c:863:5: warning: ?strncpy? output may be truncated copying 225
bytes from a string of length 255 [-Wstringop-truncation]

  863 |     strncpy(trunc_tok, tok, sizeof trunc_tok - 1);

      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




I could also try memcpy, but i don't so much like the idea of going away
from string functions for string handling.


Other suggestions are also welcome.


Brad
On Wed, Dec 11, 2024 at 1:29?PM Ivan Krylov <ikrylov at disroot.org> wrote: