This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Warning in date_and_time.c
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Jerry DeLisle <jvdelisle at charter dot net>
- Cc: gfortran <fortran at gcc dot gnu dot org>
- Date: Fri, 23 Sep 2016 10:48:00 +0300
- Subject: Re: Warning in date_and_time.c
- Authentication-results: sourceware.org; auth=none
- References: <b32b7c6e-0070-c914-ee5d-a97b615852ba@charter.net>
On Thu, Sep 22, 2016 at 6:59 PM, Jerry DeLisle <jvdelisle@charter.net> wrote:
> I just noticed this today:
>
> ../../../trunk/libgfortran/intrinsics/date_and_time.c:173:33: warning: ‘%+03d’
> directive output may be truncated writing between 3 and 9 bytes into a region of
> size 6 [-Wformat-length=]
> snprintf (zone, ZONE_LEN + 1, "%+03d%02d",
> ^~~~~
> ../../../trunk/libgfortran/intrinsics/date_and_time.c:173:32: note: directive
> argument in the range [-35791394, 35791394]
> snprintf (zone, ZONE_LEN + 1, "%+03d%02d",
> ^~~~~~~~~~~
> ../../../trunk/libgfortran/intrinsics/date_and_time.c:173:2: note: format output
> between 6 and 12 bytes into a destination of size 6
> snprintf (zone, ZONE_LEN + 1, "%+03d%02d",
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> values[3] / 60, abs (values[3] % 60));
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Does anyone know off hand what to do to fix this?
>
> Jerry
Presumably GCC doesn't know that the values are between [0,12] and
[0,60]. So if it assumes that the value can be INT_MAX then, yes, the
buffer is not large enough. Since this is a spurious warning, maybe
add something like
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-length"
/* Line 173 with the snprintf here */
#pragma GCC diagnostic pop
around the call to temporarily disable that warning?
--
Janne Blomqvist