Core dump error while returning from a function
<p>I have a function:</p>

<pre><code>void function(const string param1, string *p2param, string *retparam)
</code></pre>

<p>when this is invoked from <code>main</code>, execution goes till last line of this function and then fails with</p>

<pre><code>Bus Error(coredump)
</code></pre>

<p>The function performs some string manipulation using pointer to string and then the final value is passed to <code>*retparam</code>.</p>

<p>The code goes like this aa.c has</p>

<pre><code>string *f1;//global
string f2= "abc";//global

function_2()
{
stringstream aa;
*f1 += aa&lt;&lt;"test";
//similar concatenation
 }
function(param1, *p2param, *retparam)
{
  /* assign back the values*/
  f1 =&amp;f2;
  //call to a function from bb.c
  // from bb.c function_2() is in called
   retparam = f1
 }
</code></pre>

<p>The only information I could get is:</p>

<pre><code>pstack core
$ pstack core
core 'core' of 4517:    aa_test -t 745
 ffffffff7c67109c __1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___2T5B6M_v_ (ffffffff7fffce98, 1002805fc, 10010cc90, 0, ffffffff7c8c3bd8, ffffffff7fffce98) + 14
 0000000100004498 main (10010b000, 100000, ffffffff7fffce98, ffffffff7fffcf00, ffffffff7fffd288, ffffffff7fffd0b8) + 818
 0000000100003a7c _start (0, 0, 0, 0, 0, 0) + 17c
</code></pre>

<p>What is causing this error?</p>

<p>Thanks for your valueable inputs which finally has sorted out my issue.</p>

<p>The issue was with the typecast of string variable
code snippet</p>

<pre><code>void function(const string param1, string *p2param, string *retparam)  {  
   //function to call from bb.c has prototype
    //fun2(const char **str,stubfunc)
    const char *l_str = param1.c_str();
    fun2((const char **) &amp;l_str,coverage_hook);
}
//this was ealier called as 
//fun2((const char**) &amp;param1,coverage_hook); hence was causing the core dump 
//why?? still dont know :)
</code></pre>
