[PATCH 06/11] Add X*asprintf() routines to mirror common asprintf() routines

Alan Coopersmith alan.coopersmith at oracle.com
Tue Nov 30 15:11:06 PST 2010


Julien Cristau wrote:
> On Mon, Nov 29, 2010 at 20:57:43 -0800, Alan Coopersmith wrote:
> 
>> +/* Old api, now deprecated, may be removed in a future release */
>> +char *
>> +Xvprintf(const char *format, va_list va)
>> +{
>> +    char *ret;
>> +
>> +    Xvasprintf(&ret, format, va);
>> +
>>      return ret;
>>  }
>>  
>> @@ -68,7 +191,7 @@ char *Xprintf(const char *format, ...)
>>      char *ret;
>>      va_list va;
>>      va_start(va, format);
>> -    ret = Xvprintf(format, va);
>> +    Xvasprintf(&ret, format, va);
>>      va_end(va);
>>      return ret;
>>  }
> 
> Shouldn't these two check for -1 return from Xvasprintf?

Yes.   I was originally going to guarantee that Xvasprintf NULL'ed the pointer,
but then decided it was better not to rely on that to reduce the chances of
breaking something when moving to the direct libc calls in the future.

Fixed in v2:

@@ -181,7 +181,8 @@ Xvprintf(const char *format, va_list va)
 {
     char *ret;

-    Xvasprintf(&ret, format, va);
+    if (Xvasprintf(&ret, format, va) == -1)
+       ret = NULL;

     return ret;
 }
@@ -191,7 +192,8 @@ char *Xprintf(const char *format, ...)
     char *ret;
     va_list va;
     va_start(va, format);
-    Xvasprintf(&ret, format, va);
+    if (Xvasprintf(&ret, format, va) == -1)
+       ret = NULL;
     va_end(va);
     return ret;
 }


-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the xorg-devel mailing list