Jan Schmidt wrote:
> Damien Carbery wrote:
>> In totem 2.21.0 there are two references to asprintf().
>> This function does not appear to be in Solaris.
>>
>> The attached patch does a malloc/sprintf as a replacement (seen in 
>> patches/liboil-01-fixcompile.diff).
>>
>> Is this the correct way to do this? The liboil patch doesn't mention 
>> any free(). Should this patch?
>>
>> Damien
>>
> 
> Allocating 2k buffers for every sub-node is going to chew up more memory 
> than required.
> 
Especially since the patch for some reason allocates 8 of those on 
systems where pointers are 4 bytes (the malloc uses sizeof(char *) 
instead of sizeof(char))... Presumably a real implementation first 
calculates how many bytes are required and then allocates that, rather 
than using some arbitrary size (and an snprintf should be used for 
safety, as Alan mentioned). In this particular case, since there isn't 
really much formatting being done, the lengths of both strings could be 
computed, then a proper sized block allocated and two memcpy plus a null 
termination could be done to concatenate the two strings.

Cyrille

Reply via email to