From patchwork Thu Jan 25 18:53:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 866004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-472036-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uhNB0SeO"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zSB5H3q9Sz9s8J for ; Fri, 26 Jan 2018 05:53:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=M35VzfKv+8+DP0T9geub4RDq+x9GbOdQq4Gjng1YJcrOcqIvzs bYwRCfWaGj9zEXo4dqg40Cb1f+pX2QeXba3grnaRjoJNFyqsBoYGDg0W7g5AUSg0 2fFJAJA2nJi1AckxX68Y9r3gMK7CQ3f7WFWf4b6f/Grie9k/y4QCtMkZw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=3vGXVNuLRrFggqg/2doG9AehNCU=; b=uhNB0SeOZtH8DWtwiuSK zteex/SYhf1UmClQFPG3RHr+/OY07iuqm5mK8X1pIW95nhN5YhJbgRK4X1DcrJDH e8/Qjn+t3FWrInmK+qdnmNcOk6KecBIdZwUx+eJ4wrrwCsjfgVG1f3hce7bDBPlM ts16LyrN9rt6SRCydW1w9qQ= Received: (qmail 107750 invoked by alias); 25 Jan 2018 18:53:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 107740 invoked by uid 89); 25 Jan 2018 18:53:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=H*c:HHH X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-oln040092066076.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.92.66.76) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Jan 2018 18:53:30 +0000 Received: from VE1EUR01FT044.eop-EUR01.prod.protection.outlook.com (10.152.2.56) by VE1EUR01HT062.eop-EUR01.prod.protection.outlook.com (10.152.3.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.428.12; Thu, 25 Jan 2018 18:53:27 +0000 Received: from DB6PR0701MB2664.eurprd07.prod.outlook.com (10.152.2.59) by VE1EUR01FT044.mail.protection.outlook.com (10.152.3.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.444.13 via Frontend Transport; Thu, 25 Jan 2018 18:53:27 +0000 Received: from DB6PR0701MB2664.eurprd07.prod.outlook.com ([fe80::cd52:d52:9261:c845]) by DB6PR0701MB2664.eurprd07.prod.outlook.com ([fe80::cd52:d52:9261:c845%18]) with mapi id 15.20.0464.006; Thu, 25 Jan 2018 18:53:27 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" CC: David Malcolm Subject: [PATCH] fix for diagnostic/84034 Date: Thu, 25 Jan 2018 18:53:27 +0000 Message-ID: x-incomingtopheadermarker: OriginalChecksum:3EFB75E4E1A8C9D6BC3859BD2EFB0039315B0F858AEE07BF276C0B6A718F2120; UpperCasedChecksum:7252CC10A9B8A8A00CFE451FA9557B24D54AE77252C1BE8400CC438FBAF0E70E; SizeAsReceived:6974; Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [T2vmevzOZfccmPNl8b1nhWy0uBw5u+oi] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VE1EUR01HT062; 6:rh1EZYdNB1sFIz0Y3a6gtWTMH1VxIhWMgoNlC1FsqvP46zt3++Pi5wRsw15gclxn9lzi4VwQOcnMY12fo0Sm2oZkJ+VftPkR73zaeSsbfghC8Tj9uS7PXs6HG0KwbhqwkIpw6NOpWPd3LmfiuYSbjcqujwKRJ4038fTjCuD4VhZgTf5UMDewAPZFQaowKlb9fi1o0kvpUQfLmBeXrwvn9CAQ4XMMv/hMGC3SInxWRbqO1xOe9diFfRn6MztBHejqA5HcgCY0duty59M4sSEM1l5oeAqONgUyLp5YZV6gbTBtveevD0ZN+NUKbsDQLJF3zKIdC0cPfGkQQQzFHrpKhlbr5MVVsgQpK+okbXkKUds=; 5:hI1bxs0yK/UvdhLl1yWxzDrS4e+t7EEqpvuXZPmjy814ZdBRKDj7PFeIGNylEvH+iwwg+VyyAcQofGR8gcuRdRAp20pieKqpzCwGz8bKhfj75ZEqMGF6eE+Re5HXM9w/GdTPbVtvivkq+Y76YKQGvxZv5kZsLaZuMGxw+VbBOz8=; 24:+t4/tIhcbqDhpsdyOcMvWHdBop097xfhIuDRMMxWwQ8WvEqH6hs08S9gUDuNKH4No+6jh/gGRJNXHdo5/y6z9aHRczThpcjUzSDRtHY+QW4=; 7:XWANronKaL40iF1JKDKA4Of2fPvczrnbOZEReTc11f55+b65/i2mhTzP/GUC77bFqIUtwFlbl9nJH0PX4S83gYpaIqBGZY/2reacmVy+YIaPKcY8Q7kRG+N7JAyDJ4emBqoJrBw3bwZn/yONZ7TYn1cCJzJOaye/4BXwBNuv3BPYzsjtr15j/I8Pi8K223o2AzmkSfRi5FlZjWnSJ4XEnASxik7AyglVII6PMCgvZlI379jM6LOIgDOzL+5I7Y9h x-incomingheadercount: 45 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1603101448)(1601125374)(1701031045); SRVR:VE1EUR01HT062; x-ms-traffictypediagnostic: VE1EUR01HT062: x-ms-office365-filtering-correlation-id: 999547e4-4591-4c19-2c39-08d56424eaca x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:VE1EUR01HT062; BCL:0; PCL:0; RULEID:; SRVR:VE1EUR01HT062; x-forefront-prvs: 0563F2E8B7 x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR01HT062; H:DB6PR0701MB2664.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 999547e4-4591-4c19-2c39-08d56424eaca X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jan 2018 18:53:27.3511 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR01HT062 Hi, as PR diagnostic/84034 shows, source files with dos style line endings can cause a glitch in the terminal emulation that erases the source line that is supposed to be shown. That happens when the colorizing escape sequences are printed between the CR and the LF. Apparently the LF is being ignored and thus the following line overwrites everything from the last source line. The following patch fixes the visual glitch by handling a CR '\r' like a TAB '\t' character. Bootstrapped and reg-rested in x86_64-pc-linux-gnu. OK for trunk? Thanks Bernd. 2018-01-25 Bernd Edlinger PR diagnostic/84034 * diagnostic-show-locus.c (get_line_width_without_trailing_whitespace): Handle CR like TAB. (layout::print_source_line): Likewise. (test_get_line_width_without_trailing_whitespace): Add test cases. Index: gcc/diagnostic-show-locus.c =================================================================== --- gcc/diagnostic-show-locus.c (revision 257048) +++ gcc/diagnostic-show-locus.c (working copy) @@ -639,7 +639,7 @@ get_line_width_without_trailing_whitespace (const while (result > 0) { char ch = line[result - 1]; - if (ch == ' ' || ch == '\t') + if (ch == ' ' || ch == '\t' || ch == '\r') result--; else break; @@ -648,7 +648,8 @@ get_line_width_without_trailing_whitespace (const gcc_assert (result <= line_width); gcc_assert (result == 0 || (line[result - 1] != ' ' - && line[result -1] != '\t')); + && line[result -1] != '\t' + && line[result -1] != '\r')); return result; } @@ -673,9 +674,11 @@ test_get_line_width_without_trailing_whitespace () assert_eq ("", 0); assert_eq (" ", 0); assert_eq ("\t", 0); + assert_eq ("\r", 0); assert_eq ("hello world", 11); assert_eq ("hello world ", 11); assert_eq ("hello world \t\t ", 11); + assert_eq ("hello world\r", 11); } #endif /* #if CHECKING_P */ @@ -1176,8 +1179,8 @@ layout::print_source_line (int row, const char *li else m_colorizer.set_normal_text (); } - char c = *line == '\t' ? ' ' : *line; - if (c == '\0') + char c = *line; + if (c == '\0' || c == '\t' || c == '\r') c = ' '; if (c != ' ') {