This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/4] GDB/MI: fix and simplify mi_valid_noargs utility function
- From: Cleber Rosa <crosa at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: areis at redhat dot com, palves at redhat dot com, Cleber Rosa <crosa at redhat dot com>
- Date: Mon, 5 Oct 2015 08:46:55 -0300
- Subject: [PATCH 2/4] GDB/MI: fix and simplify mi_valid_noargs utility function
- Authentication-results: sourceware.org; auth=none
- References: <1444045617-14526-1-git-send-email-crosa at redhat dot com>
This function was supposed to check if a command that takes no
arguments was called appropriately, that is, without any arguments.
Turns out that the implementation, relying on mi_getopt, would always
return -1, either because:
* no argument was given, then the option index (*oind) would be equal
to the argument count (argc)
* the argument given did not start with a dash (arg[0] != '-')
If the command should take no arguments, then it should be OK to just
check the given argument count.
gdb/ChangeLog:
2015-10-05 Cleber Rosa <crosa@redhat.com>
* mi/mi-getopt.c (mi_valid_noargs): Simplify/fix the function by
looking at the argument count.
---
gdb/mi/mi-getopt.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/gdb/mi/mi-getopt.c b/gdb/mi/mi-getopt.c
index 0a07a39..574ccd2 100644
--- a/gdb/mi/mi-getopt.c
+++ b/gdb/mi/mi-getopt.c
@@ -95,18 +95,14 @@ mi_getopt_allow_unknown (const char *prefix, int argc, char **argv,
return mi_getopt_1 (prefix, argc, argv, opts, oind, oarg, 0);
}
+/* Tests if a command that takes no arguments was properly used.
+ Returns 1 if no options were given, otherwise return 0. */
+
int
mi_valid_noargs (const char *prefix, int argc, char **argv)
{
- int oind = 0;
- char *oarg;
- static const struct mi_opt opts[] =
- {
- { 0, 0, 0 }
- };
-
- if (mi_getopt (prefix, argc, argv, opts, &oind, &oarg) == -1)
- return 1;
- else
+ if (argc > 0)
return 0;
+
+ return 1;
}
--
2.4.3