2018-08-01 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.
@@ -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;
}
@@ -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;