diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-08-12 18:04:33 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-08-12 18:04:33 +0200 |
commit | 2f1364c2b325eec008bf461a0d77264618a9afe8 (patch) | |
tree | 2e00735b63167cdb3d3b63e5b6d1ae320e43c34a /gcc/c | |
parent | d186f41d35f7dd1190bf175b9224fa6f941ffbc0 (diff) | |
download | gcc-2f1364c2b325eec008bf461a0d77264618a9afe8.zip gcc-2f1364c2b325eec008bf461a0d77264618a9afe8.tar.gz gcc-2f1364c2b325eec008bf461a0d77264618a9afe8.tar.bz2 |
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
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 62701f0..522da71 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,11 @@ +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> PR c/7652 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 8456a0c..2e1e09d 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -8558,6 +8558,8 @@ set_nonincremental_init_from_string (tree str, wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT; 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); p = TREE_STRING_POINTER (str); end = p + TREE_STRING_LENGTH (str); @@ -8583,7 +8585,7 @@ set_nonincremental_init_from_string (tree str, bitpos = (wchar_bytes - byte - 1) * charwidth; else bitpos = byte * charwidth; - val[bitpos % HOST_BITS_PER_WIDE_INT] + val[bitpos / HOST_BITS_PER_WIDE_INT] |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++)) << (bitpos % HOST_BITS_PER_WIDE_INT); } |