> -----Original Message----- > From: Adriano dos Santos Fernandes [mailto:adrian...@gmail.com] > Sent: MiƩrcoles, 19 de Febrero de 2014 8:10 > > On 18/02/2014 19:26, Claudio Valderrama C. wrote: > > Probable because the string created by > QualifiedName.toString() goes out of scope before the > contents can be copied. While it would be more tedious to > use, I would prefer this function changed to > > > > string toString(string& out) > > > > to ensure the result is written in "out" and not in a > temporary object. > > > > > Then you need to change every routine that returns a string. > > The problem is not with this function. The problem is where > is passing a > c_str() of a temporary object.
Most objects return a string that's a data member. It doesn't matter if you copy the result or use it directly, unless the object itself is destroyed: ptr = dbb->dbb_filename.c_str() ptr = tdbb->getAttachment()->att_filename.c_str() ptr = work->dfw_name.c_str() ptr = itemInfo->name.c_str() I can use the pointer in a code section until the object is destroyed or the name is changed. I'm not saying that you can use the pointer forever, but at least in a few lines of code after calling it. QualifiedName.toString() is different because it builds a temporary just to return the result. The concatenated name doesn't exist inside QualifiedName, so the result of c_str is invalid immediately. The simplest code causes a failure ptr = qualifiedName.toString().c_str() C. ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk Firebird-Devel mailing list, web interface at https://lists.sourceforge.net/lists/listinfo/firebird-devel