From j|nghu@zh@o @end|ng |rom hotm@||@com  Thu May 30 16:54:57 2019
From: j|nghu@zh@o @end|ng |rom hotm@||@com (jing hua zhao)
Date: Thu, 30 May 2019 14:54:57 +0000
Subject: [Rd] use of buffers in sprintf and snprintf
In-Reply-To: <DB6P189MB0581F101B909FA1E2ACC509DA51F0@DB6P189MB0581.EURP189.PROD.OUTLOOK.COM>
References: <32da856c-a60a-974f-65ab-d7123e12e813@daqana.com>
 <23307.48529.773039.904392@stat.math.ethz.ch>
 <23307.49323.908367.788461@stat.math.ethz.ch>
 <CABtg=KkuVHoX1tZ=+Lr7mDFrXvn5zdf3+Wmqhnv58GXZJS2KwQ@mail.gmail.com>,
 <f3388993-5e20-d7e5-346a-785d33fab27b@daqana.com>,
 <DB6P189MB0581F101B909FA1E2ACC509DA51F0@DB6P189MB0581.EURP189.PROD.OUTLOOK.COM>
Message-ID: <DB6P189MB0581A9E34BD18A3E06B8E725A5180@DB6P189MB0581.EURP189.PROD.OUTLOOK.COM>

Hi again,

I realised it is useful to replicate the warnings locally without relying on CRAN automatic check; instead of R(-devel)  CMD check --as-cran package_version.tar.gz one can use

R CMD check --configure-args=""

and in my case the WARNINGS were initially given with https://www.stats.ox.ac.uk/pub/bdr/gcc9/README.txt and those specification might as well used in --configure-args above.

Besst regards,


Jing Hua

________________________________
From: R-devel <r-devel-bounces at r-project.org> on behalf of jing hua zhao <jinghuazhao at hotmail.com>
Sent: 29 May 2019 15:49
To: r-devel at r-project.org
Subject: [Rd] use of buffers in sprintf and snprintf

Dear R-developers,

I am struggling with packaging with sprintf and snprintf() as the following WARNINGS from gcc 9.x,

  hap_c.c:380:46: warning: ?%d? directive output may be truncated writing between 1 and 10 bytes into a region of size between 0 and 127 [-Wformat-truncation=]
  hap_c.c:392:46: warning: ?%d? directive output may be truncated writing between 1 and 10 bytes into a region of size between 0 and 127 [-Wformat-truncation=]

Essentially, I have

#define MAX_FILENAME_LEN 128
char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], tempname[MAX_FILENAME_LEN];

...

 snprintf(tempname,sizeof(tempname),"%s.%d", of1name, j);

It looks I could get around with


#define MAX_FILENAME_LEN 128

#define MAX_FILENAME_LEN2 256

char of1name[MAX_FILENAME_LEN],of2name[MAX_FILENAME_LEN], tempname[MAX_FILENAME_LEN2];

...
snprintf(tempname,2*sizeof(tempname)+1,"%s.%d", of1name, j)

It looks a bit waste of resources to me.


Any idea will be greatly appreciated,



Jing Hua

        [[alternative HTML version deleted]]


	[[alternative HTML version deleted]]



[Rd] use of buffers in sprintf and snprintf
jing hua zhao