Steve wrote:
> Ok now this has got me stumped what was unsafe about #2?
> Taking advantage of the type safety features in the standard lib, is
> what I was trying to show, and I have a lot of code running using
> both.  If thats unsafe, I have some patchin' to do.

Well, if I understand your code correctly, you're returning a char *
pointer (likely const char *) to the internal buffer of the out
stringstream, correct?  If so, then on return the caller receives a
pointer to the internal buffer of the out object which lived in the
stack frame of the itoa call, which no longer exists.


>>> char* itoa(int in){
>>>       std::stringstream out;
>>>       out << in;
>>>       return(out.rdbuf.c_str());
>>> }


/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to