|
@@ -101,6 +101,7 @@ struct state *st = &state;
|
|
/* local prototypes */
|
|
/* local prototypes */
|
|
static void set_flag(int);
|
|
static void set_flag(int);
|
|
static int contains(const char *, int);
|
|
static int contains(const char *, int);
|
|
|
|
+static int valid_option_name(const char *);
|
|
static int is_option(const char *);
|
|
static int is_option(const char *);
|
|
static void set_option(const char *);
|
|
static void set_option(const char *);
|
|
static void check_opts(void);
|
|
static void check_opts(void);
|
|
@@ -337,10 +338,13 @@ int G_parser(int argc, char **argv)
|
|
/* Stash default answers */
|
|
/* Stash default answers */
|
|
|
|
|
|
opt = &st->first_option;
|
|
opt = &st->first_option;
|
|
- while (opt) {
|
|
|
|
|
|
+ while (st->n_opts && opt) {
|
|
if (opt->required)
|
|
if (opt->required)
|
|
st->has_required = 1;
|
|
st->has_required = 1;
|
|
|
|
|
|
|
|
+ if (!valid_option_name(opt->key))
|
|
|
|
+ G_warning(_("BUG in option name, '%s' is not valid"), opt->key);
|
|
|
|
+
|
|
/* Parse options */
|
|
/* Parse options */
|
|
if (opt->options) {
|
|
if (opt->options) {
|
|
int cnt = 0;
|
|
int cnt = 0;
|
|
@@ -658,7 +662,7 @@ char *G_recreate_command(void)
|
|
}
|
|
}
|
|
|
|
|
|
opt = &st->first_option;
|
|
opt = &st->first_option;
|
|
- while (opt) {
|
|
|
|
|
|
+ while (st->n_opts && opt) {
|
|
if (opt->answer && opt->answers && opt->answers[0]) {
|
|
if (opt->answer && opt->answers && opt->answers[0]) {
|
|
slen = strlen(opt->key) + strlen(opt->answers[0]) + 4; /* +4 for: ' ' = " " */
|
|
slen = strlen(opt->key) + strlen(opt->answers[0]) + 4; /* +4 for: ' ' = " " */
|
|
if (len + slen >= nalloced) {
|
|
if (len + slen >= nalloced) {
|
|
@@ -874,6 +878,23 @@ static int contains(const char *s, int c)
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static int valid_option_name(const char *string)
|
|
|
|
+{
|
|
|
|
+ int m = strlen(string);
|
|
|
|
+ int n = strspn(string, "abcdefghijklmnopqrstuvwxyz0123456789_");
|
|
|
|
+
|
|
|
|
+ if (!m)
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+ if (m != n)
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+ if (string[m-1] == '_')
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
+
|
|
static int is_option(const char *string)
|
|
static int is_option(const char *string)
|
|
{
|
|
{
|
|
int n = strspn(string, "abcdefghijklmnopqrstuvwxyz0123456789_");
|
|
int n = strspn(string, "abcdefghijklmnopqrstuvwxyz0123456789_");
|