typeck2.c (digest_init_r): Fix overlength strings.
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 13 Sep 2018 18:43:44 +0000 (18:43 +0000)
committerJeff Law <law@gcc.gnu.org>
Thu, 13 Sep 2018 18:43:44 +0000 (12:43 -0600)
* 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
gcc/cp/typeck2.c

index ca8939d..8ba87ce 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-13  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       * 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  <ville.voutilainen@gmail.com>
 
        PR c++/87093
index 7cd0a7e..b13ed26 100644 (file)
@@ -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;
        }