From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21530 invoked by alias); 28 Nov 2017 19:26:20 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 21517 invoked by uid 89); 28 Nov 2017 19:26:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Highest X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Nov 2017 19:26:19 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0057E80465 for ; Tue, 28 Nov 2017 19:26:17 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-13.phx2.redhat.com [10.3.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2921C60317; Tue, 28 Nov 2017 19:26:16 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] Reject fix-it hints for various awkward boundary cases (PR c/82050) Date: Tue, 28 Nov 2017 19:49:00 -0000 Message-Id: <1511897329-26107-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02460.txt.bz2 PR c/82050 reports a failed assertion deep within diagnostic_show_locus's code for printing fix-it hints. The root cause is a fix-it hint suggesting a textual replacement, where the affected column numbers straddle the LINE_MAP_MAX_COLUMN_NUMBER boundary, so that the start of the range has a column number, but the end of the range doesn't. The fix is to verify that the column numbers are sane when adding fix-it hints to a rich_location, rejecting fix-it hints where they are not. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. Committed to trunk as r255214. libcpp/ChangeLog: PR c/82050 * include/line-map.h (LINE_MAP_MAX_COLUMN_NUMBER): Move here. * line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): ...from here. (rich_location::maybe_add_fixit): Reject fix-it hints in which the start column exceeds the next column. --- libcpp/include/line-map.h | 5 +++++ libcpp/line-map.c | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 8b7e5dc..1151484 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -280,6 +280,11 @@ enum lc_reason worked example in libcpp/location-example.txt. */ typedef unsigned int source_location; +/* Do not track column numbers higher than this one. As a result, the + range of column_bits is [12, 18] (or 0 if column numbers are + disabled). */ +const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); + /* Do not pack ranges if locations get higher than this. If you change this, update: gcc.dg/plugin/location-overflow-test-*.c. */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 0e5804b..ac621e9 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -26,11 +26,6 @@ along with this program; see the file COPYING3. If not see #include "internal.h" #include "hashtab.h" -/* Do not track column numbers higher than this one. As a result, the - range of column_bits is [12, 18] (or 0 if column numbers are - disabled). */ -const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); - /* Highest possible source location encoded within an ordinary or macro map. */ const source_location LINE_MAP_MAX_SOURCE_LOCATION = 0x70000000; @@ -2352,6 +2347,14 @@ rich_location::maybe_add_fixit (source_location start, stop_supporting_fixits (); return; } + /* The columns must be in the correct order. This can fail if the + endpoints straddle the boundary for which the linemap can represent + columns (PR c/82050). */ + if (exploc_start.column > exploc_next_loc.column) + { + stop_supporting_fixits (); + return; + } const char *newline = strchr (new_content, '\n'); if (newline) -- 1.8.5.3