[R-pkg-devel] Check warning around sprintf: Compiled code should not call entry points which might terminate R nor write to stdout/stderr instead of to the console, nor use Fortran I/O nor system RNGs nor [v]sprintf.
Iago Giné-Vázquez
|@go@g|n-v@z @end|ng |rom protonm@||@com
Tue Nov 21 01:24:33 CET 2023
Thanks to all for the inputs and Ivan and Martin for the cleaner code you suggest and which I will definitely use.
Iago
Sent with Proton Mail secure email.
On Monday, 20 November 2023 at 10:09, Martin Maechler <maechler using stat.math.ethz.ch> wrote:
> > > > > > Serguei Sokol
> > > > > > on Mon, 20 Nov 2023 10:04:10 +0100 writes:
>
>
> > Le 19/11/2023 à 02:07, Iris Simmons a écrit :
>
> >> Yes, the reason for the error is the use of sprintf. You can instead use
>
> >> snprintf where n is the maximum number of bytes to write, including the
>
> >> terminating nul character. For example:
>
> >>
>
> >> char msg[8191];
>
> >> snprintf(msg, 8191, "criteria: error (%d) -> %s\n", inErr, errStr);
>
> > This line should be
>
>
> > snprintf(msg, 8190, "criteria: error (%d) -> %s\n", inErr, errStr);
>
>
> > i.e. 1-less than 'msg' size, leaving a room for the terminal 0-byte.
>
> > Otherwise, a recent version of gcc emits a warning caught by CRAN.
>
>
> > Best,
>
> > Serguei.
>
>
> Yes, indeed ' - 1 ',
>
> but really Iago (and everyone else!) should in such cases
> use the much nicer and easier code that Ivan Krylov proposed
> yesterday :
>
> Rf_error("criteria: error (%d) -> %s", inErr, errStr);
>
>
> with no need of declaring a `msg` buffer and thinking about
> its size.
>
> Martin
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
More information about the R-package-devel
mailing list