[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #MZX-901611]: netcdf-3.6.2, putget.c array out of bound?



Hi Wuyin Lin,

The C standard explicitly allows the address of the first element past
the end of an array to be used in pointer arithmetic.  You can check
the C Programming Language, 2nd edition, for confirmation of this in
section 5.4 on address arithmetic.

It would lead to undefined behavior to actually dereference this element,
but it is permitted to take its address and use that in comparisons, which
is what is done in libsrc/putget.c.

Nevertheless, it would probably avoid the warning from the IBM compiler if this
were rewritten to replace

        const char *const end = &xfillp[sizeof(xfillp)];

with the equivalent

        const char *const end = xfillp + sizeof(xfillp);

instead, although it might not be as clear what is going on.

By the way, our version of xlc on AIX does not emit the warning you are
seeing.
Did you have to use some special compiler option(s) to produce more warnings?

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: MZX-901611
Department: Support netCDF
Priority: Normal
Status: Closed