Sfoglia il codice sorgente

libgis: avoid segfault on G_store(NULL)
Bugfix for v.db.connect when VAR is not available


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@41401 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 15 anni fa
parent
commit
e2426199ab
1 ha cambiato i file con 14 aggiunte e 5 eliminazioni
  1. 14 5
      lib/gis/strings.c

+ 14 - 5
lib/gis/strings.c

@@ -71,8 +71,11 @@ int G_strcasecmp(const char *x, const char *y)
  * 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 *G_store(const char *s)
 {
     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;
 }