On Fri, May 03, 2019 at 12:53:06PM +0200, Martin Liška wrote:
> 
> The patch is about suppression of the following warning:
> 
> /home/gcc/buildworker/zenith-gcc-trunk-weekly/build/libgfortran/intrinsics/date_and_time.c:165:33:
>  warning: ‘%04d’ directive output may be truncated writing between 4 and 11 
> bytes into a region of size 9 [-Wformat-truncation=]
> /home/gcc/buildworker/zenith-gcc-trunk-weekly/build/libgfortran/intrinsics/date_and_time.c:172:33:
>  warning: ‘%+03d’ directive output may be truncated writing between 3 and 9 
> bytes into a region of size 6 [-Wformat-truncation=]
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?

Why are you getting a warning?  Is this a wchar issue?

The comment in the code for DATE is 

   DATE (optional) shall be scalar and of type default character.
   It is an INTENT(OUT) argument.  It is assigned a value of the
   form CCYYMMDD, where CC is the century, YY the year within the
   century, MM the month within the year, and DD the day within the
   month.  If there is no date available, they are assigned blanks.

12345678
CCYYMMDD

That is 8 characters, so 

#define DATE_LEN 8
...
  char date[DATE_LEN + 1];

would appear to be correct.  The '+ 1' is for the terminating '\0'.

Futhermore, 'date' appears as an argument to snprintf() and
memset(), where both function will write at most DATE_LEN
characters into 'date'.

Arbitrarily, increasing the sizes of 'date' and 'zone' to
silence a bogus warning seems dubious to me.  Remove the
-W option if the false positive offends you.

-- 
Steve

Reply via email to