]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/67410 (c/c-typeck.c references out of bounds array)
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:12:08 +0000 (09:12 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:12:08 +0000 (09:12 +0200)
Backported from mainline
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.

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

From-SVN: r248596

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr67410.c [new file with mode: 0644]

index ca0fd0dc4b8f3b06839a19b81921b8d1993a2f39..bdc6b43856f59bf1561f1f8bd3ec1a0bca1cb5f9 100644 (file)
@@ -1,6 +1,14 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       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-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/72816
index 15a1fc9b315f05faaffcf0324788ef983b5a594f..8f3086e38f9e4bd58b10ad62df583f7945e22719 100644 (file)
@@ -8248,6 +8248,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);
@@ -8273,7 +8275,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);
            }
index eccc05634545919ded2202390a389fdc1aaf0ef5..4f031a919ad283072e50ba99a0200908fdda9bbf 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/67410
+       * gcc.dg/pr67410.c: New test.
+
        2016-08-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/72868
diff --git a/gcc/testsuite/gcc.dg/pr67410.c b/gcc/testsuite/gcc.dg/pr67410.c
new file mode 100644 (file)
index 0000000..ff3c4f1
--- /dev/null
@@ -0,0 +1,15 @@
+/* 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;
+}