From: David Malcolm Date: Fri, 19 Dec 2014 20:11:16 +0000 (+0000) Subject: Fix issue with string options and nested gcc_jit_contexts X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5afd44e33b13b922760a41580020f941dbdd473e;p=gcc.git Fix issue with string options and nested gcc_jit_contexts 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 --- diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog index 639f8e6cd9c..8f3f412126e 100644 --- a/gcc/jit/ChangeLog +++ b/gcc/jit/ChangeLog @@ -1,3 +1,9 @@ +2014-12-19 David Malcolm + + * 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 * jit-recording.c (gcc::jit::recording::context::set_str_option): diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c index 7d9da247392..6613ed7af34 100644 --- a/gcc/jit/jit-recording.c +++ b/gcc/jit/jit-recording.c @@ -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));