[PATCH v4 6/7] Replace alloc+strcpy+strcat with asprintf() & XNFasprintf() calls
walter harms
wharms at bfs.de
Mon Dec 6 05:38:02 PST 2010
Am 06.12.2010 09:34, schrieb Alan Coopersmith:
> walter harms wrote:
>>
>> Am 05.12.2010 18:51, schrieb Alan Coopersmith:
>>
>>>>> diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c
>>>>> index ce86090..c0fa80a 100644
>>>>> --- a/hw/xfree86/common/xf86ShowOpts.c
>>>>> +++ b/hw/xfree86/common/xf86ShowOpts.c
>>>>> @@ -97,11 +97,8 @@ void DoShowOptions (void) {
>>>>> );
>>>>> continue;
>>>>> }
>>>>> - pSymbol = malloc(
>>>>> - strlen(xf86DriverList[i]->driverName) + strlen("ModuleData") + 1
>>>>> - );
>>>>> - strcpy (pSymbol, xf86DriverList[i]->driverName);
>>>>> - strcat (pSymbol, "ModuleData");
>>>>> + XNFasprintf(&pSymbol, "%sModuleData",
>>>>> + xf86DriverList[i]->driverName);
>>>>
>>>> every code before checks the return value of asprintf but not here ?
>>> We don't need to know the length, and error is not an option from the XNF*
>>> variants - they either succeed or cause the server to abort. I used the
>>> XNF* here since if the malloc failed, previously the server exited, just
>>> going through the sigsegv handler instead of a cleaner AbortServer().
>>> (NF is "No Fail")
>>>
>>
>>
>> mmh, so XNFasprintf() could be void instead of int ?
>
> If we were sure that no caller would ever want the returned string length - but
> we're not, and that would be a needless change from the normal asprintf() API.
>
but this is not the normal asprintf() but you are right it makes sense to have a length
so you can use realloc to increase it, or you drop it and use
asprintf(&mod,"%s%",mod,mod2) to append.
Do you realy think anyone whould use it ? people we use it as errorindicator and what
value has an errorindicator in a function that can not fail ?
re,
wh
More information about the xorg-devel
mailing list