<div dir="ltr">OK, I did a quick search and there are 104 calls to Vect_open_new. 63 calls don't check its return value and 41 calls check. 27 of the 41 that do the check do some cleaning work before finally throwing a fatal error. Most of the cleaning work is Vect_close(already open vectors), which I don't think is really necessary before throwing a fatal error. v.convert fcloses Digin and v.surf.rst deletes left-over files. Even Vect_close returns 1. Based on these observations, I think Vect_open_new needs to return what it's returning now on failure and the 63 calls that don't check its return value have to be fixed to avoid a potential segmentation fault. I'll fix them tonight if I didn't overlook something.<div>
<br></div><div>53 files that don't check the return value:</div><div><br></div><div><div>./display/d.extract/main.c</div><div>./lib/sites/sites.c</div><div>./raster/r.carve/vect.c</div><div>./raster/r.contour/main.c</div>
<div>./raster/r.random/random.c</div><div>./raster/r.stream.extract/close.c</div><div>./raster/r.stream.order/stream_vector.c</div><div>./raster/r.stream.segment/stream_vector.c</div></div><div><div>./raster/r.stream.snap/points_io.c</div>
<div>./raster/r.to.vect/main.c</div><div>./raster/r.volume/main.c</div><div>./raster/simwe/simlib/output.c</div><div>./vector/v.buffer/main.c</div><div>./vector/v.build.polylines/main.c</div><div>./vector/v.build/main.c</div>
<div>./vector/v.clean/main.c</div><div>./vector/v.distance/main.c</div><div>./vector/v.drape/main.c</div><div>./vector/v.edit/main.c</div><div>./vector/v.external/main.c</div><div>./vector/v.extract/main.c</div><div>./vector/v.extrude/main.c</div>
<div>./vector/v.in.ascii/main.c</div><div>./vector/v.in.dwg/main.c</div><div>./vector/v.in.lidar/main.c</div><div>./vector/v.in.ogr/main.c</div><div>./vector/v.in.region/main.c</div><div>./vector/v.in.sites/main.c</div><div>
./vector/v.kernel/main.c</div><div>./vector/v.lrs/v.lrs.create/main.c</div><div>./vector/v.lrs/v.lrs.label/main.c</div><div>./vector/v.lrs/v.lrs.segment/main.c</div><div>./vector/v.net.alloc/main.c</div><div>./vector/v.net.iso/main.c</div>
<div>./vector/v.net.salesman/main.c</div><div>./vector/v.net.steiner/main.c</div><div>./vector/v.overlay/main.c</div><div>./vector/v.parallel/main.c</div><div>./vector/v.patch/main.c</div><div>./vector/v.perturb/main.c</div>
<div>./vector/v.proj/main.c</div><div>./vector/v.qcount/main.c</div><div>./vector/v.reclass/main.c</div><div>./vector/v.rectify/main.c</div><div>./vector/v.sample/main.c</div><div>./vector/v.segment/main.c</div><div>./vector/v.select/main.c</div>
<div>./vector/v.split/main.c</div><div>./vector/v.surf.rst/main.c</div><div>./vector/v.to.points/main.c</div><div>./vector/v.transform/main.c</div><div>./vector/v.vol.rst/main.c</div><div>./vector/v.voronoi/main.c</div></div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 2, 2014 at 1:18 PM, Huidae Cho <span dir="ltr"><<a href="mailto:grass4u@gmail.com" target="_blank">grass4u@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">More detail.. When this happens, Map is not fully initialized and following Vect_* calls with Map can fail unexpectedly, which caused a segmentation fault in this case.</div>
<div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Fri, May 2, 2014 at 1:15 PM, Huidae Cho <span dir="ltr"><<a href="mailto:grass4u@gmail.com" target="_blank">grass4u@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">Segmentation fault when you do v.in.db ... output=a@other_mapset because Vect_open_new returns -1 with a warning, not a fatal error, "unable to create new ... is not the current mapset". I didn't check why it's returning -1 instead of throwing a fatal error in this case. I believe that this warning has to be a fatal error if no modules rely on -1 return.<span><font color="#888888"><div>


<br></div><div>Huidae</div></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 2, 2014 at 12:59 PM, Martin Landa <span dir="ltr"><<a href="mailto:landa.martin@gmail.com" target="_blank">landa.martin@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
2014-05-02 18:53 GMT+02:00  <<a href="mailto:svn_grass@osgeo.org" target="_blank">svn_grass@osgeo.org</a>>:<br>
<div><br>
> -    Vect_open_new(&Map, outvect->answer, with_z);<br>
> +    if (Vect_open_new(&Map, outvect->answer, with_z) == -1)<br>
> +       exit(EXIT_FAILURE);<br>
> +<br>
<br>
</div>please provide more info where it fails. Also note that Vect_open_new<br>
calls G_fatal_error() so the most of modules don't check return code<br>
of this function.<br>
<span><font color="#888888"><br>
Martin<br>
<br>
--<br>
Martin Landa * <a href="http://geo.fsv.cvut.cz/gwiki/Landa" target="_blank">http://geo.fsv.cvut.cz/gwiki/Landa</a><br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>