From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119659 invoked by alias); 16 Jul 2015 16:41:51 -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 119640 invoked by uid 89); 16 Jul 2015 16:41:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f50.google.com Received: from mail-pa0-f50.google.com (HELO mail-pa0-f50.google.com) (209.85.220.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 16 Jul 2015 16:41:47 +0000 Received: by pacan13 with SMTP id an13so45695711pac.1 for ; Thu, 16 Jul 2015 09:41:45 -0700 (PDT) X-Received: by 10.66.119.174 with SMTP id kv14mr20172013pab.5.1437064905267; Thu, 16 Jul 2015 09:41:45 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id si3sm2656130pac.5.2015.07.16.09.41.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jul 2015 09:41:44 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] Fix using uninitialised values Date: Thu, 16 Jul 2015 16:41:00 -0000 Message-Id: <1437064895-23973-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg00480.txt.bz2 We did a code refacotr here https://sourceware.org/ml/gdb-patches/2013-11/msg00063.html > (get_current_thread): New function, factored out from ... > (add_current_inferior_and_thread): ... this. Adjust. > >@@ -3332,18 +3371,8 @@ add_current_inferior_and_thread (char *wait_status) > > inferior_ptid = null_ptid; > >- /* Now, if we have thread information, update inferior_ptid. First >- if we have a stop reply handy, maybe it's a T stop reply with a >- "thread" register we can extract the current thread from. If >- not, ask the remote which is the current thread, with qC. The >- former method avoids a roundtrip. Note we don't use >- remote_parse_stop_reply as that makes use of the target >- architecture, which we haven't yet fully determined at this >- point. */ >- if (wait_status != NULL) >- ptid = stop_reply_extract_thread (wait_status); >- if (ptid_equal (ptid, null_ptid)) >- ptid = remote_current_thread (inferior_ptid); >+ /* Now, if we have thread information, update inferior_ptid. */ >+ ptid = get_current_thread (wait_status); but after the refactor, local variable ptid is used without initialisation. However, before this change, ptid is initialised to null_ptid. This error can be found by valgrind too... ==3298== at 0x6B99BA: ptid_equal (ptid.c:80) ==3298== by 0x4C67FF: get_current_thread (remote.c:3484) ==3298== by 0x4C6951: add_current_inferior_and_thread (remote.c:3511) ==3298== by 0x4C762C: extended_remote_create_inferior (remote.c:8506) ==3298== by 0x5A5312: run_command_1 (infcmd.c:606) ==3298== by 0x68B4FB: execute_command (top.c:463) ==3298== by 0x5C7214: command_handler (event-top.c:494) ==3298== by 0x5C78A3: command_line_handler (event-top.c:692) ==3298== by 0x6DEB57: rl_callback_read_char (callback.c:220) ==3298== by 0x5C7278: rl_callback_read_char_wrapper (event-top.c:171) ==3298== by 0x5C72C2: stdin_event_handler (event-top.c:432) ==3298== by 0x5C6194: gdb_wait_for_event (event-loop.c:834) This patch initialises local variable ptid to null in get_current_thread. We don't need to initialise ptid in add_current_inferior_and_thread, so this patch also removes the ptid initialisation. Regression tested on x86_64-linux on gdbserver. gdb: 2015-07-16 Yao Qi * remote.c (get_current_thread): Initialise ptid to null_ptid. (add_current_inferior_and_thread): Don't initialise ptid. --- gdb/remote.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 9d97f6b..94899bd 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3474,7 +3474,7 @@ stop_reply_extract_thread (char *stop_reply) static ptid_t get_current_thread (char *wait_status) { - ptid_t ptid; + ptid_t ptid = null_ptid; /* Note we don't use remote_parse_stop_reply as that makes use of the target architecture, which we haven't yet fully determined at @@ -3503,7 +3503,7 @@ add_current_inferior_and_thread (char *wait_status) { struct remote_state *rs = get_remote_state (); int fake_pid_p = 0; - ptid_t ptid = null_ptid; + ptid_t ptid; inferior_ptid = null_ptid; -- 1.9.1