[PATCH:libX11 7/7] Convert more sprintf calls to snprintf

Alan Coopersmith alan.coopersmith at oracle.com
Sun Feb 17 10:36:41 PST 2013


On 02/17/13 10:32 AM, walter harms wrote:
>> @@ -190,7 +191,7 @@ XGetErrorDatabaseText(
>>  	else
>>  	    tptr = Xmalloc (tlen);
>>  	if (tptr) {
>> -	    sprintf(tptr, "%s.%s", name, type);
>> +	    snprintf(tptr, tlen, "%s.%s", name, type);
>>  	    XrmGetResource(db, tptr, "ErrorType.ErrorNumber",
>>  	      &type_str, &result);
>>  	    if (tptr != temp)
> 
> 
> perhaps an asprintf() is more nice here ?

If you look at the full context, it's only doing the malloc when the temporary
stack buffer it uses isn't large enough:

http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/ErrDes.c#n185

Plus we don't have an asprintf fallback implementation in libX11 yet, and we
still support a number of older releases without asprintf in libc yet.

-- 
	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc


More information about the xorg-devel mailing list