You could use memcpy instead. That gets rids of the type checking though.

You could also define something like char * my_strncpy ( char *
destination, const char * source, size_t num ) { return (char *)
memcpy(destination, source, num) } to keep the type checking.

On Wed, Dec 11, 2024, 07:12 Brad Eck <bradleyj...@gmail.com> wrote:

> Dear List
>
> The latest update to my epanet2toolkit package bounced from CRAN due to
> some warnings about string truncation in C code from gcc.
>
> 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]
>     input2.c:302:15: warning: ‘__builtin_strncpy’ output may be truncated
> copying 78 bytes from a string of length 1024 [-Wstringop-truncation]
>     report.c:795:9: warning: ‘__builtin_strncpy’ output may be truncated
> copying 967 bytes from a string of length 1024 [-Wstringop-truncation]
>
> The package wraps a simulation engine that parses inputs from and
> writes results to text files. 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.
>
> Any suggestions on how to carry out a truncation so that gcc won't
> complain?
>
> Thanks in advance,
>
> Brad
>
> PS - CRAN check info is here
>
> https://win-builder.r-project.org/incoming_pretest/epanet2toolkit_1.0.6_20241209_221743/specialChecks/
>
> PPS the latest CRAN submission is from this branch
> https://github.com/bradleyjeck/epanet2toolkit/tree/lto-crash
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

        [[alternative HTML version deleted]]

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

Reply via email to