From patchwork Sun Dec 1 19:32:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36408 Received: (qmail 60735 invoked by alias); 1 Dec 2019 19:32:13 -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 60705 invoked by uid 89); 1 Dec 2019 19:32:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Dec 2019 19:32:10 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id ABA3C2039A; Sun, 1 Dec 2019 14:32:08 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 4468D20391; Sun, 1 Dec 2019 14:32:07 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 15A5F2816F; Sun, 1 Dec 2019 14:32:07 -0500 (EST) X-Gerrit-PatchSet: 2 Date: Sun, 1 Dec 2019 14:32:06 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Tom Tromey , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [pushed] Fix latent bug in tui_copy_source_line X-Gerrit-Change-Id: I46cdabe6e57549983149b8f640cda5edd16fa260 X-Gerrit-Change-Number: 683 X-Gerrit-ChangeURL: X-Gerrit-Commit: 517d261dfafb7e5317b841b01ab853a76deb8128 In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191201193207.15A5F2816F@gnutoolchain-gerrit.osci.io> The original change was created by Tom Tromey. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/683 ...................................................................... Fix latent bug in tui_copy_source_line tui_copy_source_line has a bug, where it can advance past the terminating \0 in its input string. This patch fixes the bug and adds a test case for this function. gdb/ChangeLog 2019-12-01 Tom Tromey * tui/tui-winsource.c (tui_copy_source_line): Don't advance past \0. * unittests/tui-selftests.c: New file. * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add tui-selftests.c. Change-Id: I46cdabe6e57549983149b8f640cda5edd16fa260 --- M gdb/ChangeLog M gdb/Makefile.in M gdb/tui/tui-winsource.c A gdb/unittests/tui-selftests.c 4 files changed, 58 insertions(+), 0 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 67b76dc..e61b08b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2019-12-01 Tom Tromey + * tui/tui-winsource.c (tui_copy_source_line): Don't advance past + \0. + * unittests/tui-selftests.c: New file. + * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add tui-selftests.c. + +2019-12-01 Tom Tromey + * tui/tui.c (tui_enable): Call tui_update_variables earlier. 2019-12-01 Tom Tromey diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 58f5f93..e5c8faa 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -442,6 +442,7 @@ unittests/string_view-selftests.c \ unittests/style-selftests.c \ unittests/tracepoint-selftests.c \ + unittests/tui-selftests.c \ unittests/unpack-selftests.c \ unittests/utils-selftests.c \ unittests/vec-utils-selftests.c \ diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 81937c1..6653709 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -103,6 +103,8 @@ lineptr += skip_bytes; continue; } + if (c == '\0') + break; ++lineptr; ++column; diff --git a/gdb/unittests/tui-selftests.c b/gdb/unittests/tui-selftests.c new file mode 100644 index 0000000..3a5d34f --- /dev/null +++ b/gdb/unittests/tui-selftests.c @@ -0,0 +1,48 @@ +/* Self tests for the TUI + + Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" +#include "gdbsupport/selftest.h" +#include "tui/tui-winsource.h" + +namespace selftests { +namespace tui { + +static void +run_tests () +{ + const char *text = "hello"; + std::string result = tui_copy_source_line (&text, 0, 0, 50, 0); + SELF_CHECK (result == "hello"); + SELF_CHECK (*text == '\0'); + + text = "hello\n"; + result = tui_copy_source_line (&text, 0, 0, 3, 0); + SELF_CHECK (result == "hel"); + SELF_CHECK (*text == '\0'); +} + +} /* namespace tui*/ +} /* namespace selftests */ + +void +_initialize_tui_selftest () +{ + selftests::register_test ("tui", selftests::tui::run_tests); +}