[GRASS-SVN] r55411 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 17 09:41:49 PDT 2013


Author: martinl
Date: 2013-03-17 09:41:49 -0700 (Sun, 17 Mar 2013)
New Revision: 55411

Modified:
   grass/trunk/lib/vector/Vlib/level_two.c
Log:
Vect_get_node_coor: return -1 on invalid index


Modified: grass/trunk/lib/vector/Vlib/level_two.c
===================================================================
--- grass/trunk/lib/vector/Vlib/level_two.c	2013-03-17 14:41:14 UTC (rev 55410)
+++ grass/trunk/lib/vector/Vlib/level_two.c	2013-03-17 16:41:49 UTC (rev 55411)
@@ -263,17 +263,22 @@
    \brief Get node coordinates
 
    \param Map pointer to Map_info struct
-   \param num node id
-   \param x,y,z coordinates values (for 2D coordinates z is NULL)
+   \param num node id (starts at 1)
+   \param[out] x,y,z coordinates values (for 2D coordinates z is NULL)
 
-   \return 0
+   \return 0 on success
+   \return -1 on error
  */
-int
-Vect_get_node_coor(const struct Map_info *Map, int num, double *x, double *y,
-		   double *z)
+int Vect_get_node_coor(const struct Map_info *Map, int num, double *x, double *y,
+                       double *z)
 {
     struct P_node *Node;
 
+    if (num < 1 || num > Map->plus.n_nodes) {
+        G_warning(_("Invalid node id: %d"), num);
+        return -1;
+    }
+    
     Node = Map->plus.Node[num];
     *x = Node->x;
     *y = Node->y;
@@ -281,7 +286,7 @@
     if (z != NULL)
 	*z = Node->z;
 
-    return (0);
+    return 0;
 }
 
 /*!



More information about the grass-commit mailing list