В Wed, 11 Dec 2024 12:12:11 +0000
Brad Eck <bradleyj...@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

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to