From: Cleber Rosa <crosa@redhat.com>
To: gdb-patches@sourceware.org
Cc: areis@redhat.com, palves@redhat.com, Cleber Rosa <crosa@redhat.com>
Subject: [PATCH 2/4] GDB/MI: fix and simplify mi_valid_noargs utility function
Date: Mon, 05 Oct 2015 11:47:00 -0000 [thread overview]
Message-ID: <1444045617-14526-3-git-send-email-crosa@redhat.com> (raw)
In-Reply-To: <1444045617-14526-1-git-send-email-crosa@redhat.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
next prev parent reply other threads:[~2015-10-05 11:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 11:47 [PATCH 0/4]: GDB: inferior standard I/O redirection Cleber Rosa
2015-10-05 11:47 ` [PATCH 1/4] " Cleber Rosa
2015-10-05 12:23 ` Eli Zaretskii
2015-10-21 11:18 ` Pedro Alves
2015-10-05 11:47 ` [PATCH 3/4] GDB/MI: add test for command -inferior-tty-show Cleber Rosa
2015-10-21 11:19 ` Pedro Alves
2015-10-05 11:47 ` Cleber Rosa [this message]
2015-10-21 11:19 ` [PATCH 2/4] GDB/MI: fix and simplify mi_valid_noargs utility function Pedro Alves
2015-10-05 11:54 ` [PATCH 4/4] GDB/MI: inferior standard I/O redirection Cleber Rosa
2015-10-05 12:26 ` Eli Zaretskii
2015-10-21 11:19 ` Pedro Alves
2015-10-22 10:55 ` Vladimir Prus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444045617-14526-3-git-send-email-crosa@redhat.com \
--to=crosa@redhat.com \
--cc=areis@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox