From patchwork Tue Feb 12 19:46:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31428 Received: (qmail 68422 invoked by alias); 12 Feb 2019 19:46:26 -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 68413 invoked by uid 89); 12 Feb 2019 19:46:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.164) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Feb 2019 19:46:24 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 20D2CDBF1C for ; Tue, 12 Feb 2019 13:46:23 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id te0dgUwOoiQerte0dgkPjZ; Tue, 12 Feb 2019 13:46:23 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=mw8XMbpfZD5eVvKTPXQJmlOUuHftuBvE3rHmxrYdqHA=; b=UnPzZD/TJk1nv66gOwcuYa/Z3t sbvSKdwE2ciCZ4GYdN/Yad7XvUMJpnJ91gXkxSo+mv2cBRal8Kmi/wKTKrTLBFRH7GOwpAyw4Nz5g 3QtX1G6eG18LvPktrGSeTeVG6; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:40082 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gte0c-004DmS-Tz; Tue, 12 Feb 2019 13:46:23 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix some valgrind errors in the TUI Date: Tue, 12 Feb 2019 12:46:21 -0700 Message-Id: <20190212194621.13988-1-tom@tromey.com> The styling series introduced some new errors in the TUI -- the series changed how source lines are allocated, without updating tui_set_source_content_nil. There are several failures but a typical one looks like: ==6274== Use of uninitialised value of size 8 ==6274== at 0x4E4A095: wclrtoeol (in /usr/lib64/libncursesw.so.6.1) ==6274== by 0x4E47617: waddch (in /usr/lib64/libncursesw.so.6.1) ==6274== by 0x8325CB: tui_puts_internal(_win_st*, char const*, int*) (tui-io.c:393) ==6274== by 0x82E89D: tui_file::puts(char const*) (tui-file.c:39) ==6274== by 0x84BF5F: vfprintf_unfiltered(ui_file*, char const*, __va_list_tag*) (utils.c:2026) This patch rewrites tui_set_source_content_nil, fixing the bug. This was also reported as PR tui/24197. Verified by running valgrind before and after on x86-64 Fedora 29. gdb/ChangeLog 2019-02-12 Tom Tromey PR tui/24197: * tui/tui-source.c (tui_set_source_content_nil): Rewrite. --- gdb/ChangeLog | 5 +++++ gdb/tui/tui-source.c | 21 +++++---------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index a7e801eba26..7cc3c00069c 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -253,33 +253,22 @@ tui_set_source_content_nil (struct tui_win_info *win_info, if (curr_line == (n_lines / 2 + 1)) { - int i; int xpos; int warning_length = strlen (warning_string); char *src_line; - src_line = element->which_element.source.line; - if (warning_length >= ((line_width - 1) / 2)) xpos = 1; else xpos = (line_width - 1) / 2 - warning_length; - for (i = 0; i < xpos; i++) - src_line[i] = ' '; - - sprintf (src_line + i, "%s", warning_string); - - for (i = xpos + warning_length; i < line_width; i++) - src_line[i] = ' '; - - src_line[i] = '\n'; - - } /* end if */ + src_line = xstrprintf ("%s%s", n_spaces (xpos), warning_string); + xfree (element->which_element.source.line); + element->which_element.source.line = src_line; + } curr_line++; - - } /* end while */ + } }