Pārlūkot izejas kodu

bugfix https://trac.osgeo.org/grass/ticket/1557 (g.list segmentation fault)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50562 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 gadi atpakaļ
vecāks
revīzija
ad24f9a2a6
2 mainītis faili ar 28 papildinājumiem un 10 dzēšanām
  1. 8 6
      general/g.list/main.c
  2. 20 4
      lib/manage/do_list.c

+ 8 - 6
general/g.list/main.c

@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
     if (!mapset)
 	mapset = "";
 
-    if (G_strcasecmp(mapset, ".") == 0)
+    if (strcmp(mapset, ".") == 0)
 	mapset = G_mapset();
 
     i = 0;
@@ -74,11 +74,13 @@ int main(int argc, char *argv[])
 
 	if (full->answer) {
 	    char lister[GPATH_MAX];
-
-	    sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
-		    M_get_list(n)->element[0]);
-	    G_debug(3, "lister CMD: %s", lister);
-	    if (access(lister, 1) == 0)	/* execute permission? */
+	    
+	    if (n > -1) {
+		sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
+			M_get_list(n)->element[0]);
+		G_debug(3, "lister CMD: %s", lister);
+	    }
+	    if (n > -1 && access(lister, 1) == 0) /* execute permission? */
 		G_spawn(lister, lister, mapset, NULL);
 	    else
 		M_do_list(n, mapset);

+ 20 - 4
lib/manage/do_list.c

@@ -3,7 +3,7 @@
   
   \brief Manage Library - List elements
   
-  (C) 2001-2011 by the GRASS Development Team
+  (C) 2001-2012 by the GRASS Development Team
  
   This program is free software under the GNU General Public License
   (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -12,16 +12,32 @@
 */
 
 #include <grass/gis.h>
+#include <grass/glocale.h>
 
 #include "manage_local_proto.h"
 
 /*!
   \brief List elements
 
-  \param n element id
-  \param mapset name of mapset
+  \param n element index in the array (negative value for all elements)
+  \param mapset name of mapset ("" for search path)
 */
 void M_do_list(int n, const char *mapset)
 {
-    G_list_element(list[n].element[0], list[n].desc[0], mapset, (int (*)())0);
+    int i;
+    
+    if (n >= nlist) {
+	G_fatal_error(_("%s: invalid index %d"), "M_do_list()", n);
+    }
+    
+    if (n < 0) {
+	for (i = 0; i < nlist; i++) {
+	    G_list_element(list[i].element[0], list[i].desc[0],
+			   mapset, (int (*)())0);
+	}
+    }
+    else {
+	G_list_element(list[n].element[0], list[n].desc[0],
+		       mapset, (int (*)())0);
+    }
 }