[postgis-tickets] [PostGIS] #5558: Compilation warning: uninitialized variable
PostGIS
trac at osgeo.org
Fri Sep 29 05:23:27 PDT 2023
#5558: Compilation warning: uninitialized variable
---------------------------+---------------------------
Reporter: Laurenz Albe | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.4.1
Component: postgis | Version: master
Resolution: | Keywords:
---------------------------+---------------------------
Description changed by Laurenz Albe:
Old description:
> Building master, I get
>
> {{{
> In file included from mvt.h:40,
> from mvt.c:30:
> mvt.c: In function ‘mvt_clip_and_validate_geos’:
> mvt.c:884:41: warning: ‘bgbox.flags’ may be used uninitialized [-Wmaybe-
> uninitialized]
> 884 | FLAGS_SET_GEODETIC(bgbox.flags, 0);
> ../liblwgeom/liblwgeom.h:175:95: note: in definition of macro
> ‘FLAGS_SET_GEODETIC’
> 175 | #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ?
> ((flags) | LWFLAG_GEODETIC) : ((flags) & ~LWFLAG_GEODETIC))
> |
> ^~~~~
> mvt.c:881:22: note: ‘bgbox’ declared here
> 881 | GBOX bgbox;
> | ^~~~~
> }}}
>
> Indeed, in `postgis/mvt.c`, `bgbox.flag` is not initialized:
>
> {{{#!c
> GBOX bgbox;
> bgbox.xmax = bgbox.ymax = (double)extent + (double)buffer;
> bgbox.xmin = bgbox.ymin = -(double)buffer;
> FLAGS_SET_GEODETIC(bgbox.flags, 0);
> }}}
>
> I guess it should be initialized to zero, as in the following patch:
>
> {{{#!diff
> diff --git a/postgis/mvt.c b/postgis/mvt.c
> index 8aa916052..64bb28edb 100644
> --- a/postgis/mvt.c
> +++ b/postgis/mvt.c
> @@ -881,6 +881,7 @@ mvt_clip_and_validate_geos(LWGEOM *lwgeom, uint8_t
> basic_type, uint32_t extent,
> GBOX bgbox;
> bgbox.xmax = bgbox.ymax = (double)extent + (double)buffer;
> bgbox.xmin = bgbox.ymin = -(double)buffer;
> + bgbox.flags = 0;
> FLAGS_SET_GEODETIC(bgbox.flags, 0);
>
> ng = mvt_unsafe_clip_by_box(ng, &bgbox);
> }}}
New description:
Building master, I get
{{{
In file included from mvt.h:40,
from mvt.c:30:
mvt.c: In function ‘mvt_clip_and_validate_geos’:
mvt.c:884:41: warning: ‘bgbox.flags’ may be used uninitialized [-Wmaybe-
uninitialized]
884 | FLAGS_SET_GEODETIC(bgbox.flags, 0);
../liblwgeom/liblwgeom.h:175:95: note: in definition of macro
‘FLAGS_SET_GEODETIC’
175 | #define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ?
((flags) | LWFLAG_GEODETIC) : ((flags) & ~LWFLAG_GEODETIC))
|
^~~~~
mvt.c:881:22: note: ‘bgbox’ declared here
881 | GBOX bgbox;
| ^~~~~
}}}
Indeed, in `postgis/mvt.c`, `bgbox.flag` is not initialized:
{{{#!c
GBOX bgbox;
bgbox.xmax = bgbox.ymax = (double)extent + (double)buffer;
bgbox.xmin = bgbox.ymin = -(double)buffer;
FLAGS_SET_GEODETIC(bgbox.flags, 0);
}}}
I cannot suggest a patch, because I don't know to what value the `flags`
should be initialized.
--
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5558#comment:1>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list