[PATCH:libXv 1/7] Remove unnecessary casts from Xmalloc calls
Alan Coopersmith
alan.coopersmith at oracle.com
Mon Jun 24 08:58:37 PDT 2013
On 06/24/13 02:12 AM, walter harms wrote:
>
>
> Am 23.06.2013 20:53, schrieb Alan Coopersmith:
>> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
>> ---
>> src/Xv.c | 14 +++++++-------
>> 1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/src/Xv.c b/src/Xv.c
>> index ee80959..5df5464 100644
>> --- a/src/Xv.c
>> +++ b/src/Xv.c
>> @@ -190,7 +190,7 @@ XvQueryAdaptors(
>> }
>>
>> size = rep.length << 2;
>> - if ((buffer = (char *) Xmalloc((unsigned) size)) == NULL) {
>> + if ((buffer = Xmalloc(size)) == NULL) {
>
> IMHO this is more readable:
>
> buffer = Xmalloc(size);
> if (bufffer == NULL ) {
Yes, but the if ((buffer = Xmalloc(size)) == NULL) is a common style
in X.Org code, and wasn't the problem I'm looking to solve here.
>> @@ -237,7 +237,7 @@ XvQueryAdaptors(
>> size = u.pa->name_size;
>> u.buffer += (sz_xvAdaptorInfo + 3) & ~3;
>>
>> - if ((name = (char *) Xmalloc(size + 1)) == NULL) {
>> + if ((name = Xmalloc(size + 1)) == NULL) {
>> XvFreeAdaptorInfo(pas);
>> Xfree(buffer);
>> UnlockDisplay(dpy);
>
>
> is it possible that this is a version of asprintf() here ?
No. This code is taking a length-counted, non-nil-terminated
string from the wire protocol and converting it to a standard
C style nil-terminated string.
It would probably be suitable for strndup(), but that's not
universally supported yet.
--
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Engineering - http://blogs.oracle.com/alanc
More information about the xorg-devel
mailing list