This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning in date_and_time.c


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]