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.
|