From patchwork Sun Apr 26 15:17:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 6455 Received: (qmail 67724 invoked by alias); 26 Apr 2015 15:17:30 -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 67714 invoked by uid 89); 26 Apr 2015 15:17:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qk0-f172.google.com Received: from mail-qk0-f172.google.com (HELO mail-qk0-f172.google.com) (209.85.220.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 26 Apr 2015 15:17:28 +0000 Received: by qkx62 with SMTP id 62so51951219qkx.0 for ; Sun, 26 Apr 2015 08:17:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5JAlTLb7SzP0HIujbXZpUNlBLO2mmhcGsBagP1ShzkU=; b=XjYnojLWhT903NXC299CkfR6BCnJDZervT3OucvsmnyRdNaNQFm12z8IFk0LPFBhoQ w3FRoLg/rAhPtdodWITDzlZVzRpJQc2qYpU9q1Fhc2FlffptMdxPJTBAwbTvSEXUJg6a jMztHo+Ymg4d5icZ+YpwUBqTrfHK3rbiIDW8/D1z2yZTWCncD6GWz+eR3liWUM/TfnPQ 4i/Lw1esMAceOh5S9DX//lVkuExoxBAoRlet8GKNwtxvPKHqvtOtPiWnZy5K/gaGO1Or i1mnbzafU0wClpVmoUTaFal3jN4icpdDGdW8ZSll25PhYp/IwSDTCqDQ3QrXzd25/IxV vA0Q== X-Gm-Message-State: ALoCoQm2Tg6wAZtbFqTJqaWymeVRgI3f33bAxdQgnGe00qb07h2WRM3G1F0BG+6/IYRFxd34ZxO6 X-Received: by 10.55.52.4 with SMTP id b4mr8218745qka.37.1430061446699; Sun, 26 Apr 2015 08:17:26 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id z69sm10495497qkz.27.2015.04.26.08.17.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Apr 2015 08:17:25 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] TUI: avoid calling strcpy() on indentical string objects Date: Sun, 26 Apr 2015 11:17:20 -0400 Message-Id: <1430061440-20379-1-git-send-email-patrick@parcs.ath.cx> In tui_set_source_content(), when offset == 0 the source and destination pointers of the call to strcpy() are actually the same. In this case not only is strcpy() unnecessary but it is also UB when the two strings overlap. gdb/ChangeLog: * tui/tui-source.c (tui_set_source_content): Avoid calling strcpy() when offset is 0. --- gdb/tui/tui-source.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 31df0c8..018a1df 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -218,7 +218,9 @@ tui_set_source_content (struct symtab *s, } /* Now copy the line taking the offset into account. */ - if (strlen (src_line) > offset) + if (offset == 0) + ; + else if (strlen (src_line) > offset) strcpy (TUI_SRC_WIN->generic.content[cur_line] ->which_element.source.line, &src_line[offset]);