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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 7 03:45:52 EDT 2011


Author: martinl
Date: 2011-07-07 00:45:52 -0700 (Thu, 07 Jul 2011)
New Revision: 47036

Modified:
   grass/trunk/lib/gis/parser.c
   grass/trunk/lib/gis/parser_help.c
Log:
libgis: avoid segfault when opt->key is not defined
	minor changes in doxygen


Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c	2011-07-07 07:26:28 UTC (rev 47035)
+++ grass/trunk/lib/gis/parser.c	2011-07-07 07:45:52 UTC (rev 47036)
@@ -218,20 +218,7 @@
 
     opt->required = NO;
     opt->multiple = NO;
-    opt->answer = NULL;
-    opt->answers = NULL;
-    opt->def = NULL;
-    opt->checker = NULL;
-    opt->options = NULL;
-    opt->key_desc = NULL;
-    opt->gisprompt = NULL;
-    opt->label = NULL;
-    opt->opts = NULL;
-    opt->description = NULL;
-    opt->descriptions = NULL;
-    opt->guisection = NULL;
-    opt->guidependency = NULL;
-
+    
     st->current_option = opt;
     st->n_opts++;
 
@@ -245,7 +232,6 @@
     G_zero(item, sizeof(struct Item));
 
     item->option = opt;
-    item->flag = NULL;
 
     st->current_item = item;
     st->n_items++;

Modified: grass/trunk/lib/gis/parser_help.c
===================================================================
--- grass/trunk/lib/gis/parser_help.c	2011-07-07 07:26:28 UTC (rev 47035)
+++ grass/trunk/lib/gis/parser_help.c	2011-07-07 07:45:52 UTC (rev 47036)
@@ -1,19 +1,20 @@
 /*!
- * \file gis/parser_help.c
- *
- * \brief GIS Library - Argument parsing functions (help)
- *
- * (C) 2001-2009 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.
- *
- * \author Original author CERL
- * \author Soeren Gebbert added Dec. 2009 WPS process_description document
- */
+  \file lib/gis/parser_help.c
+ 
+  \brief GIS Library - Argument parsing functions (help)
+  
+  (C) 2001-2009, 2011 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.
+  
+  \author Original author CERL
+  \author Soeren Gebbert added Dec. 2009 WPS process_description document
+*/
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <grass/gis.h>
 #include <grass/glocale.h>
@@ -25,25 +26,25 @@
 static int show(FILE *fp, const char *item, int len);
 
 /*!
- * \brief Command line help/usage message.
- *
- * Calls to G_usage() allow the programmer to print the usage
- * message at any time. This will explain the allowed and required
- * command line input to the user. This description is given according
- * to the programmer's definitions for options and flags. This function
- * becomes useful when the user enters options and/or flags on the
- * command line that are syntactically valid to the parser, but
- * functionally invalid for the command (e.g. an invalid file name.)
- *
- * For example, the parser logic doesn't directly support grouping
- * options. If two options be specified together or not at all, the
- * parser must be told that these options are not required and the
- * programmer must check that if one is specified the other must be as
- * well. If this additional check fails, then G_parser() will succeed,
- * but the programmer can then call G_usage() to print the standard
- * usage message and print additional information about how the two
- * options work together.
- */
+  \brief Command line help/usage message.
+  
+  Calls to G_usage() allow the programmer to print the usage
+  message at any time. This will explain the allowed and required
+  command line input to the user. This description is given according
+  to the programmer's definitions for options and flags. This function
+  becomes useful when the user enters options and/or flags on the
+  command line that are syntactically valid to the parser, but
+  functionally invalid for the command (e.g. an invalid file name.)
+  
+  For example, the parser logic doesn't directly support grouping
+  options. If two options be specified together or not at all, the
+  parser must be told that these options are not required and the
+  programmer must check that if one is specified the other must be as
+  well. If this additional check fails, then G_parser() will succeed,
+  but the programmer can then call G_usage() to print the standard
+  usage message and print additional information about how the two
+  options work together.
+*/
 void G_usage(void)
 {
     usage(stderr, 0);
@@ -122,6 +123,10 @@
 	    else
 		key_desc = "value";
 
+	    if (!opt->key) {
+		fprintf(stderr, "\n%s\n", _("ERROR: Option key not defined"));
+		exit(EXIT_FAILURE);
+	    }
 	    n = strlen(opt->key);
 	    if (n > maxlen)
 		maxlen = n;



More information about the grass-commit mailing list