From 0a4b0aa140d187faa2f72da821de428a6a557da7 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Thu, 13 Sep 2018 18:43:44 +0000 Subject: [PATCH] typeck2.c (digest_init_r): Fix overlength strings. * typeck2.c (digest_init_r): Fix overlength strings. * vtable-class-hierarchy.c (build_key_buffer_arg): Make string literal NUL terminated. From-SVN: r264286 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck2.c | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ca8939d9a08..8ba87ce3894 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-09-13 Bernd Edlinger + + * typeck2.c (digest_init_r): Fix overlength strings. + * vtable-class-hierarchy.c (build_key_buffer_arg): Make string literal + NUL terminated. + 2018-09-13 Ville Voutilainen PR c++/87093 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 7cd0a7ef4b4..b13ed2660de 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1112,8 +1112,13 @@ digest_init_r (tree type, tree init, int nested, int flags, 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"); + + init = build_string (size, TREE_STRING_POINTER (init)); + TREE_TYPE (init) = type; + } } return init; } -- 2.30.2