|
From: Luigi S. <gi...@li...> - 2003-04-01 14:10:09
|
On Tue, Apr 01, 2003 at 11:37:28AM +0200, Per Westermark wrote: > Your implementation of itoa would leak memory - normally itoa would use a > static buffer that is overwritten at each call. I agree that mine is just a try, also I wish to learn from your comment. My code has a memory leak because of: - user will almost always forget to call "free" (shortly: bad designed code) - there is a bug in the code (shortly: bugged code) - both bad design and bad code By the way, a call to "strcpy" does copy the piece of an array up-to the '\0', does the function "free" return memory up-to the '\0' or does it free the whole array (as I assume) ? > > A better itoa would build the buffer from the end, i.e. *p-- = ch > thereby removing need for reversing the string. I'll try to follow this advice too. > /Per W Thanks Per -- >> gisan >> |