Hi!

This is an alternative approach to handle overlength strings in the C++ FE.

The difference to the previous version is that overlength
STRING_CST never have a longer TREE_STRING_LENGTH than the TYPE_DOMAIN.
And those STRING_CSTs are thus no longer zero terminated.

Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.
2018-08-01  Bernd Edlinger  <bernd.edlin...@hotmail.de>

	* typeck2.c (digest_init_r): Fix overlength strings.
	* vtable-class-hierarchy.c (build_key_buffer_arg): Make string literal
	NUL terminated.

Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c	(revision 263807)
+++ gcc/cp/typeck2.c	(working copy)
@@ -1116,8 +1116,13 @@ digest_init_r (tree type, tree init, int nested, i
 		 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;
 	}
Index: gcc/cp/vtable-class-hierarchy.c
===================================================================
--- gcc/cp/vtable-class-hierarchy.c	(revision 263807)
+++ gcc/cp/vtable-class-hierarchy.c	(working copy)
@@ -738,7 +738,7 @@ build_key_buffer_arg (tree base_ptr_var_decl)
   tree ret_value;
 
   /* Set the len and hash for the string.  */
-  *value_ptr = len1;
+  *value_ptr = len1++;
   value_ptr++;
   *value_ptr = hash_value;
 

Reply via email to