[R-pkg-devel] building on CRAN: GCC 12 truncation warning, attempted fix not working

Gillian Sharer g||||@n @end|ng |rom |r|@@w@@h|ngton@edu
Fri Mar 25 18:59:04 CET 2022


Thank you. That worked.

-Gillian

----- Original Message -----
> From: "Simon Urbanek" <simon.urbanek using R-project.org>
> To: "gillian" <gillian using iris.washington.edu>
> Cc: "r-package-devel" <r-package-devel using r-project.org>
> Sent: Wednesday, March 23, 2022 3:47:43 PM
> Subject: Re: [R-pkg-devel] building on CRAN: GCC 12 truncation warning, attempted fix not working

> Gillian,
> 
> the buffer has to have enough space for the content *and* a terminating NUL
> character, so you need total of at least 12 bytes. Given that stack is
> typically aligned at 8-bytes I'd simply use 16 for safety.
> 
> Cheers,
> Simon
> 
> 
> 
>> On Mar 24, 2022, at 11:04 AM, Gillian Sharer <gillian using iris.washington.edu>
>> wrote:
>> 
>> We have some C code in our IRISSeismic package that has starting generating
>> truncation warnings with GCC 12.
>> 
>> This is the original code and warning:
>> 
>> 
>> char seqnum[7];
>> 
>> snprintf (seqnum, 7, "%06d", msr->sequence_number);
>> 
>> 
>> 
>> 
>> warning: ' %06d' directive output may be truncated writing between 6 and 11
>> bytes into a region of size 7 [-Wformat-truncation=]
>> 
>> 
>> 
>> 
>> This was our attempted fix and new warning:
>> 
>> char seqnum[11];
>> 
>> snprintf (seqnum, sizeof(seqnum), "%06d", msr->sequence_number);
>> 
>> 
>> 
>> 
>> warning: ' snprintf' output may be truncated before the last format character
>> [-Wformat-truncation=]
>> 
>> 
>> 
>> 
>> I don't have much experience with C and I'm not sure why the attempted fix
>> didn't work. Does anyone have advice on what else I can try to fix this?
>> 
>> 
>> 
>> 
>> 
>> Thanks,
>> 
>> Gillian Sharer
>> 
>> IRIS DMC
>> 
>> 
>> 
>> 	[[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> 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