From patchwork Mon Oct 5 11:46:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cleber Rosa X-Patchwork-Id: 8921 Received: (qmail 95831 invoked by alias); 5 Oct 2015 11:47:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95774 invoked by uid 89); 5 Oct 2015 11:47:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 05 Oct 2015 11:47:10 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 303418C1A8 for ; Mon, 5 Oct 2015 11:47:09 +0000 (UTC) Received: from x220.tallawa.org (ovpn-113-80.phx2.redhat.com [10.3.113.80]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t95Bl8UF004694; Mon, 5 Oct 2015 07:47:08 -0400 From: Cleber Rosa To: gdb-patches@sourceware.org Cc: areis@redhat.com, palves@redhat.com, Cleber Rosa Subject: [PATCH 2/4] GDB/MI: fix and simplify mi_valid_noargs utility function Date: Mon, 5 Oct 2015 08:46:55 -0300 Message-Id: <1444045617-14526-3-git-send-email-crosa@redhat.com> In-Reply-To: <1444045617-14526-1-git-send-email-crosa@redhat.com> References: <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 * 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; }