aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2009-11-01 01:06:52 -0400
committerJason Merrill <jason@gcc.gnu.org>2009-11-01 01:06:52 -0400
commitc86f25e8ea6708147f15f4e80fca192ff2e81c19 (patch)
treeb35068aa73a35aaaacc39241156eb587f8960fbf
parent691a1b27dc12ad8994c852cc26c53ca7e9a6ed39 (diff)
downloadgcc-c86f25e8ea6708147f15f4e80fca192ff2e81c19.zip
gcc-c86f25e8ea6708147f15f4e80fca192ff2e81c19.tar.gz
gcc-c86f25e8ea6708147f15f4e80fca192ff2e81c19.tar.bz2
* rtti.c (tinfo_name): Fix lengths for private case.
From-SVN: r153789
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/rtti.c6
-rw-r--r--gcc/testsuite/ChangeLog2
-rw-r--r--gcc/testsuite/g++.dg/rtti/typeid9.C21
4 files changed, 30 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 594b2c6..8ea0001 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2009-10-31 Jason Merrill <jason@redhat.com>
+ * rtti.c (tinfo_name): Fix lengths for private case.
+
+2009-10-31 Jason Merrill <jason@redhat.com>
+
PR c++/41754
* call.c (compare_ics): Avoid bad union use when
comparing two ck_lists.
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 2926f97..c7af74a 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -364,10 +364,10 @@ tinfo_name (tree type, bool mark_private)
if (mark_private)
{
/* Inject '*' at beginning of name to force pointer comparison. */
- char* buf = (char*) XALLOCAVEC (char, length + 1);
+ char* buf = (char*) XALLOCAVEC (char, length + 2);
buf[0] = '*';
- memcpy (buf + 1, name, length);
- name_string = build_string (length + 1, buf);
+ memcpy (buf + 1, name, length + 1);
+ name_string = build_string (length + 2, buf);
}
else
name_string = build_string (length + 1, name);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e26126e..aedb60b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
2009-10-31 Jason Merrill <jason@redhat.com>
+ * g++.dg/rtti/typeid9.C: New.
+
PR c++/41754
* g++.dg/cpp0x/initlist25.C: New.
diff --git a/gcc/testsuite/g++.dg/rtti/typeid9.C b/gcc/testsuite/g++.dg/rtti/typeid9.C
new file mode 100644
index 0000000..381252d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/typeid9.C
@@ -0,0 +1,21 @@
+// Test that the typeid name for a local class is properly null-terminated.
+// { dg-do run }
+
+#include <string.h>
+#include <typeinfo>
+#include <stdio.h>
+
+int f()
+{
+ struct A {}; struct B {};
+ const std::type_info &ti = typeid(A);
+ const std::type_info &ti2 = typeid(B);
+ puts (ti.name());
+ puts (ti2.name());
+ return strcmp (ti.name(), "Z1fvE1A") || strcmp (ti2.name(), "Z1fvE1B");
+}
+
+int main()
+{
+ return f();
+}