From patchwork Wed Aug 1 11:27:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 952099 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-482872-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="m40BBmEE"; 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 41gWHm0YKJz9s0R for ; Wed, 1 Aug 2018 21:27:29 +1000 (AEST) 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:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=fev8QAz8IAljIHI1NPODY/fai0M4Q/yLQ2M/dq7QzLE3Kw8fzmtib MdW9lLB2y9tHfvfo7AElcErT+iL9SLD1k79b9C4T58i2jffTikVc0+/gQHSPVC2a Z90tV53K50Ui360A27UuM556MEw41+uvNMOd4uIm83ddWJ5MCqbXlk= 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:subject:date:message-id:content-type:mime-version; s= default; bh=rQRbdfMARycxREZ6nCKTrNTLGAE=; b=m40BBmEEeO1PcuRicmnX ASH0/4zeB5OEksyqmue0Z3IeSAf6UjOr1ixfd5GwlZ6fM7qTX5sKl2qgs4rHYEnw Wxy8ArDKFonR94kg9gMfZRKYF0bAaQ8/Sua9ceA5DLLy9IdOrW2Ou/EAF6PETx9F 88BXpNVyW7So8Ib94C7xypU= Received: (qmail 90685 invoked by alias); 1 Aug 2018 11:27:22 -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 90664 invoked by uid 89); 1 Aug 2018 11:27:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR02-AM5-obe.outbound.protection.outlook.com Received: from mail-oln040092067092.outbound.protection.outlook.com (HELO EUR02-AM5-obe.outbound.protection.outlook.com) (40.92.67.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Aug 2018 11:27:19 +0000 Received: from AM5EUR02FT013.eop-EUR02.prod.protection.outlook.com (10.152.8.52) by AM5EUR02HT047.eop-EUR02.prod.protection.outlook.com (10.152.9.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.1038.3; Wed, 1 Aug 2018 11:27:17 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com (10.152.8.58) by AM5EUR02FT013.mail.protection.outlook.com (10.152.8.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.1038.3 via Frontend Transport; Wed, 1 Aug 2018 11:27:17 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::b1fe:1b4f:88c3:5243]) by AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::b1fe:1b4f:88c3:5243%9]) with mapi id 15.20.1017.010; Wed, 1 Aug 2018 11:27:17 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jason Merrill , Nathan Sidwell Subject: [PATCH] Handle overlength strings in C++ FE Date: Wed, 1 Aug 2018 11:27:17 +0000 Message-ID: received-spf: None (protection.outlook.com: hotmail.de does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=bernd.edlinger@hotmail.de; MIME-Version: 1.0 Hi, this makes too long string constants shorter, and fixes one place where a string constant is created non-zero terminated. This is a cleanup in preparation of a more thorough check on the STRING_CST objects in the middle-end. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd. 2018-08-01 Bernd Edlinger * typeck2.c (digest_init_r): Fix overlength strings. * vtable-class-hierarchy.c (build_key_buffer_arg): Make string literal NUL terminated. diff -pur gcc/cp/typeck2.c gcc/cp/typeck2.c --- gcc/cp/typeck2.c 2018-06-27 04:59:44.000000000 +0200 +++ gcc/cp/typeck2.c 2018-08-01 06:57:15.275041272 +0200 @@ -1105,8 +1105,23 @@ digest_init_r (tree type, tree init, int counted in the length of the constant, but in C++ this would be invalid. */ if (size < TREE_STRING_LENGTH (init)) - permerror (loc, "initializer-string for array " - "of chars is too long"); + { + permerror (loc, "initializer-string for array " + "of chars is too long"); + if (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))) + { + unsigned unit + = TYPE_PRECISION (TREE_TYPE (type)) / BITS_PER_UNIT; + const char *p = TREE_STRING_POINTER (init); + char *q = (char *)xmalloc (size + unit); + + memcpy (q, p, size); + memset (q + size, 0, unit); + init = build_string (size + unit, q); + TREE_TYPE (init) = type; + free (q); + } + } } return init; } diff -pur gcc/cp/vtable-class-hierarchy.c gcc/cp/vtable-class-hierarchy.c --- gcc/cp/vtable-class-hierarchy.c 2018-01-03 11:03:58.000000000 +0100 +++ gcc/cp/vtable-class-hierarchy.c 2018-08-01 09:13:38.522646005 +0200 @@ -738,7 +738,7 @@ build_key_buffer_arg (tree base_ptr_var_ tree ret_value; /* Set the len and hash for the string. */ - *value_ptr = len1; + *value_ptr = len1++; value_ptr++; *value_ptr = hash_value;