[PATCH:libX11 7/7] Convert more sprintf calls to snprintf
walter harms
wharms at bfs.de
Sun Feb 17 11:06:25 PST 2013
Am 17.02.2013 19:36, schrieb Alan Coopersmith:
> 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.
>
i see, not having a asprintf replacement is a death sentence here.
ntl you could drop the whole static buffer stuff by using asprintf()
maybe later.
just one note: i think you can eliminate same else stuff (and improve readability)
by moving
result.addr = (XPointer) defaultp;
result.size = strlen(defaultp) + 1;
this up.
when XrmGetResource() is successful it regets overwritter, if not you have
always a valid default.
re,
wh
More information about the xorg-devel
mailing list