[R-pkg-devel] truncating strings on purpose
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Wed Dec 11 14:29:30 CET 2024
В Wed, 11 Dec 2024 12:12:11 +0000
Brad Eck <bradleyjeck using gmail.com> пишет:
> Found the following significant warnings:
> input2.c:863:5: warning: ‘__builtin_strncpy’ output may be
> truncated copying 225 bytes from a string of length 255
> [-Wstringop-truncation]
> Where the truncation warnings appear, I am truncating on purpose
> using `strncpy` to avoid overflows later. I believe this works fine
> from an application point of view but the warnings remain.
GCC documentation suggests setting the length argument to _one less_
than sizeof destination buffer in addition to terminating the string:
https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wstringop-truncation
strncpy(trunc_s1, s1, sizeof trunc_s1 - 1);
trunc_s1[sizeof trunc_s1 - 1] = '\0';
--
Best regards,
Ivan
More information about the R-package-devel
mailing list