[GRASS-dev] bug in vector network analysis node costs

Štěpán Turek stepan.turek at seznam.cz
Mon Jun 10 13:29:30 PDT 2013

Hi all,

Probably I found bug in nodes cost in vector network analysis (tested in G7,
probably it affects all branches). Problem is in lib/vector/Vlib/net.c:

int cost;


(* dglInt32_t)(dglInt32_t) & cost

int cost is cast into dglInt32_t pointer. DGLib dglInt32_t is long.  I am 
relatively new to C so I do not understand the way it is casted and I can 
miss something. I am reading it as cast address of  cost int to  dglInt32_t 
and then to pointer to dglInt32_t. It does not make sense to me but it 
compiles :-) 

The problem is when you have on your system different size of long and int, 
it is probably also the reason why it was not noticed so far (on 32 bit 
usually sizeof(int) == sizeof(long)). Because it seems that during this cast
there are added bytes to be same size as long. However these bytes have 
random values and therefore results costs do not make sense. 

If this change is made everything seems ok:

dglInt32_t dgl_cost;


dgl_cost = cost;

dglNodeSet_Attr(gr, dglGetNode(gr, (dglInt32_t) cat),

& dgl_cost);

Now there is:

dglNodeSet_Attr(gr, dglGetNode(gr, (dglInt32_t) cat),

(* dglInt32_t)(dglInt32_t) & cost);

I have attached also patch.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20130610/af64e5a4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nodes_costs.diff
Type: application/octet-stream
Size: 857 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20130610/af64e5a4/attachment.obj>

More information about the grass-dev mailing list