Fix issue with string options and nested gcc_jit_contexts
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 19 Dec 2014 20:11:16 +0000 (20:11 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Fri, 19 Dec 2014 20:11:16 +0000 (20:11 +0000)
gcc/jit/ChangeLog:
* jit-recording.c (gcc::jit::recording::context::context): When
copying string options from a parent context, take a copy of the
underlying buffers, rather than simply copying the pointer.

From-SVN: r218972

gcc/jit/ChangeLog
gcc/jit/jit-recording.c

index 639f8e6cd9ccb2fa24a63c8cb8cd89a6c11ce3b9..8f3f412126e97f16301dbf97437888819b26d2d9 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-19  David Malcolm  <dmalcolm@redhat.com>
+
+       * jit-recording.c (gcc::jit::recording::context::context): When
+       copying string options from a parent context, take a copy of the
+       underlying buffers, rather than simply copying the pointer.
+
 2014-12-19  David Malcolm  <dmalcolm@redhat.com>
 
        * jit-recording.c (gcc::jit::recording::context::set_str_option):
index 7d9da24739237aefe7dc6ed44a2157266432c858..6613ed7af34f040ec68aab65d72842c0ce16d3b5 100644 (file)
@@ -181,11 +181,14 @@ recording::context::context (context *parent_ctxt)
 {
   if (parent_ctxt)
     {
-      /* Inherit options from parent.
-        Note that the first memcpy means copying pointers to strings.  */
-      memcpy (m_str_options,
-             parent_ctxt->m_str_options,
-             sizeof (m_str_options));
+      /* Inherit options from parent.  */
+      for (unsigned i = 0;
+          i < sizeof (m_str_options) / sizeof (m_str_options[0]);
+          i++)
+       {
+         const char *parent_opt = parent_ctxt->m_str_options[i];
+         m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
+       }
       memcpy (m_int_options,
              parent_ctxt->m_int_options,
              sizeof (m_int_options));