[Rd] use of buffers in sprintf and snprintf

jing hua zhao j|nghu@zh@o @end|ng |rom hotm@||@com
Wed May 29 17:49:05 CEST 2019


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]]



More information about the R-devel mailing list