View Single Post
Old 07-22-2004, 03:46 PM   #3
welcor
Member
 
Join Date: Apr 2002
Location: Aarhus, Denmark, Europe
Posts: 59
welcor is on a distinguished road
Send a message via ICQ to welcor
Well, the scope of the variable 'buf' is only the function. After the last } it simply stopped being valid. This doesn't mean it'll crash right away, as you just noted. However, the correct code, using str_dup allocates a new memory section and returns a pointer to it. If you remember to clean it up afterwards (when you're done with it), there should be no problems.

In this case you are probably calling something like
newprompt = substitutedoubledollars(oldprompt);

Just remember to free newprompt before the end of the function and you should be alright.
welcor is offline   Reply With Quote