From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17069 invoked by alias); 2 Dec 2013 06:41:37 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17028 invoked by uid 89); 2 Dec 2013 06:41:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.2 required=5.0 tests=AWL,BAYES_50,GARBLED_BODY,RDNS_NONE autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Dec 2013 06:41:35 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VnNC5-0000VA-J9 from Yao_Qi@mentor.com ; Sun, 01 Dec 2013 22:41:21 -0800 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sun, 1 Dec 2013 22:41:21 -0800 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Sun, 1 Dec 2013 22:41:20 -0800 Message-ID: <529C2B33.20102@codesourcery.com> Date: Mon, 02 Dec 2013 06:41:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Pedro Alves CC: Subject: Re: [PATCH] Fix PR remote/15974 References: <1385782688-375-1-git-send-email-yao@codesourcery.com> <5299A894.70100@redhat.com> In-Reply-To: <5299A894.70100@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00014.txt.bz2 On 11/30/2013 04:57 PM, Pedro Alves wrote: > Instead of setting and unsetting NC at each iteration, the "canonical" way > for this sort of thing is to check whether the loop ended: > > - if (nc == NULL) > + for (i == ARRAY_SIZE (notifs)) > > And then again, we don't really need NC in the loop. I think > this would look cleaner and clearer: OK, you've fixed that bug :). Pushed it for you. -- Yao (齐尧) Subject: [PATCH] Fix PR remote/15974 In remote-notif.c:handle_notification, we have a loop, for (i = 0; i < ARRAY_SIZE (notifs); i++) { nc = notifs[i]; if (strncmp (buf, nc->name, strlen (nc->name)) == 0 && buf[strlen (nc->name)] == ':') break; } /* We ignore notifications we don't recognize, for compatibility with newer stubs. */ if (nc == NULL) return; If the notification is not in the list 'notifs', the last entry is used, which is wrong. It should be NULL. This patch fixes it. gdb: 2013-12-02 Pedro Alves PR remote/15974 * remote-notif.c (handle_notification): Return early if no notification is found. --- gdb/remote-notif.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c index 0d59279..163979d 100644 --- a/gdb/remote-notif.c +++ b/gdb/remote-notif.c @@ -127,22 +127,25 @@ remote_async_get_pending_events_handler (gdb_client_data data) void handle_notification (struct remote_notif_state *state, char *buf) { - struct notif_client *nc = NULL; - int i; + struct notif_client *nc; + size_t i; for (i = 0; i < ARRAY_SIZE (notifs); i++) { - nc = notifs[i]; - if (strncmp (buf, nc->name, strlen (nc->name)) == 0 - && buf[strlen (nc->name)] == ':') + const char *name = notifs[i]->name; + + if (strncmp (buf, name, strlen (name)) == 0 + && buf[strlen (name)] == ':') break; } /* We ignore notifications we don't recognize, for compatibility with newer stubs. */ - if (nc == NULL) + if (i == ARRAY_SIZE (notifs)) return; + nc = notifs[i]; + if (state->pending_event[nc->id] != NULL) { /* We've already parsed the in-flight reply, but the stub for some -- 1.7.7.6