
Hello Eric, Am Montag 30 Januar 2012 20:18:15 schrieb Eric Blake:
+ if (diff > 0) { + tmp = realloc((void *)*buf, new_len);
We should not be using realloc in this file, but should be using VIR_RESIZE_N or similar.
Okay, makes the code even more readable.
+ memmove(token_start, replacement, replacement_len);
But this would be more efficient as memcpy, since replacement (better not) overlap with token_start.
I know of some projects which forbid memcpy() because of the missing overlap handling. But if this is okay with libvirt, I'll use it. I hope performance will never be a problem with this simple test scenario, because then doing one realloc() instead of one for each found would be better.
+ if (diff < 0) { + tmp = realloc((void *)*buf, new_len);
No need to downsize the allocation - it's okay to leave junk in the tail end of the buffer, as long as we have a trailing NUL to stop us in time.
Fine with me for this simple test case, but if that would be generalized and be used in other places, this might become a problem. I'll add a comment. Sincerely Philipp -- Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH Linux for Your Business fon: +49 421 22 232- 0 Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99 http://www.univention.de/