[GRASS-SVN] r41401 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 12 09:04:08 EST 2010


Author: martinl
Date: 2010-03-12 09:04:08 -0500 (Fri, 12 Mar 2010)
New Revision: 41401

Modified:
   grass/trunk/lib/gis/strings.c
Log:
libgis: avoid segfault on G_store(NULL)
Bugfix for v.db.connect when VAR is not available


Modified: grass/trunk/lib/gis/strings.c
===================================================================
--- grass/trunk/lib/gis/strings.c	2010-03-12 13:58:39 UTC (rev 41400)
+++ grass/trunk/lib/gis/strings.c	2010-03-12 14:04:08 UTC (rev 41401)
@@ -71,8 +71,11 @@
  * This routine allocates enough memory to hold the string <b>s</b>,
  * copies <b>s</b> to the allocated memory, and returns a pointer
  * to the allocated memory.
- * 
- *  \param[in] s string
+ *
+ * If <em>s</em> is NULL then empty string is returned.
+ *
+ *  \param s string
+ *
  *  \return pointer to newly allocated string
  */
 
@@ -80,9 +83,15 @@
 {
     char *buf;
 
-    buf = G_malloc(strlen(s) + 1);
-    strcpy(buf, s);
-
+    if (s == NULL) {
+	buf = G_malloc(sizeof(char));
+	buf[0] = '\0';
+    }
+    else {
+	buf = G_malloc(strlen(s) + 1);
+	strcpy(buf, s);
+    }
+    
     return buf;
 }
 



More information about the grass-commit mailing list