[GRASS-dev] [GRASS GIS] #2438: Vect_get_line_type cannot handle line out of range
GRASS GIS
trac at osgeo.org
Mon Oct 20 07:51:01 PDT 2014
#2438: Vect_get_line_type cannot handle line out of range
--------------------------+-------------------------------------------------
Reporter: artegion | Owner: grass-dev@…
Type: defect | Status: reopened
Priority: normal | Milestone: 6.4.5
Component: LibVector | Version: unspecified
Resolution: | Keywords:
Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by artegion):
* status: closed => reopened
* resolution: invalid =>
Comment:
Replying to [comment:1 mmetz]:
> Replying to [ticket:2438 artegion]:
> > calling Vect_get_line_type with line out of range (i.e. line=0)
> > Vect_line_alive returns -1 but Vect_get_line_type ignores it (not -1
is False just like not 1) -> access violation reading ....
>
> This is a programmer's error. 'Vect_get_line_type()' assumes that the
programmer first tested if the provided line id is indeed valid. You did
call 'Vect_line_alive()' first, you can only proceed if the line is alive.
Fix your code.
For sure calling 'Vect_get_line_type()' with a wrong line id is a
programmer error but 'Vect_get_line_type()' already call
'Vect_line_alive()'.
{{{
258 int Vect_get_line_type(const struct Map_info *Map, int line)
259 {
260 check_level(Map);
261
262 if (!Vect_line_alive(Map, line))
263 return 0;
264
265 return (Map->plus.Line[line]->type);
266 }
}}}
Testing if (!Vect_line_alive(Map, line)) is wrong because Vect_line_alive
returns[[BR]]
1 feature alive[[BR]]
0 feature is dead[[BR]]
-1 on error[[BR]]
a small change ( if (Vect_line_alive(Map, line!=1)) may improve code
robustness.
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2438#comment:2>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list