Commit 2f1364c2 by Jakub Jelinek Committed by Jakub Jelinek

re PR c/67410 (c/c-typeck.c references out of bounds array)

	PR c/67410
	* c-typeck.c (set_nonincremental_init_from_string): Use / instead of
	% to determine val element to change.  Assert that
	wchar_bytes * charwidth fits into val array.

	* gcc.dg/pr67410.c: New test.

Co-Authored-By: Martin Liska <mliska@suse.cz>

From-SVN: r239419
parent d186f41d
2016-08-12 Jakub Jelinek <jakub@redhat.com>
Martin Liska <mliska@suse.cz>
PR c/67410
* c-typeck.c (set_nonincremental_init_from_string): Use / instead of
% to determine val element to change. Assert that
wchar_bytes * charwidth fits into val array.
2016-08-12 Marek Polacek <polacek@redhat.com> 2016-08-12 Marek Polacek <polacek@redhat.com>
PR c/7652 PR c/7652
......
...@@ -8558,6 +8558,8 @@ set_nonincremental_init_from_string (tree str, ...@@ -8558,6 +8558,8 @@ set_nonincremental_init_from_string (tree str,
wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT; wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
charwidth = TYPE_PRECISION (char_type_node); charwidth = TYPE_PRECISION (char_type_node);
gcc_assert ((size_t) wchar_bytes * charwidth
<= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
type = TREE_TYPE (constructor_type); type = TREE_TYPE (constructor_type);
p = TREE_STRING_POINTER (str); p = TREE_STRING_POINTER (str);
end = p + TREE_STRING_LENGTH (str); end = p + TREE_STRING_LENGTH (str);
...@@ -8583,7 +8585,7 @@ set_nonincremental_init_from_string (tree str, ...@@ -8583,7 +8585,7 @@ set_nonincremental_init_from_string (tree str,
bitpos = (wchar_bytes - byte - 1) * charwidth; bitpos = (wchar_bytes - byte - 1) * charwidth;
else else
bitpos = byte * charwidth; bitpos = byte * charwidth;
val[bitpos % HOST_BITS_PER_WIDE_INT] val[bitpos / HOST_BITS_PER_WIDE_INT]
|= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++)) |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
<< (bitpos % HOST_BITS_PER_WIDE_INT); << (bitpos % HOST_BITS_PER_WIDE_INT);
} }
......
2016-08-12 Jakub Jelinek <jakub@redhat.com>
PR c/67410
* gcc.dg/pr67410.c: New test.
2016-08-12 Bin Cheng <bin.cheng@arm.com> 2016-08-12 Bin Cheng <bin.cheng@arm.com>
PR tree-optimization/69848 PR tree-optimization/69848
......
/* PR c/67410 */
/* { dg-do run } */
/* { dg-options "-std=gnu11" } */
struct {
__CHAR16_TYPE__ s[2];
} a[] = { u"ff", [0].s[0] = u'x', [1] = u"\u1234\u4567", [1].s[0] = u'\u89ab' };
int
main ()
{
if (a[0].s[0] != u'x' || a[0].s[1] != u'f' || a[1].s[0] != u'\u89ab' || a[1].s[1] != u'\u4567')
__builtin_abort ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment