[PATCH] xf86-video-mga: replace deprecated X*alloc functions

Alan Coopersmith alan.coopersmith at oracle.com
Mon Apr 4 15:29:28 PDT 2011


On 04/ 4/11 03:24 PM, Nicolas Kaiser wrote:
> * Ian Romanick <idr at freedesktop.org>:
>> On 04/02/2011 11:17 AM, Nicolas Kaiser wrote:
>>> diff --git a/src/mga_dri.c b/src/mga_dri.c
>>> index 2723dd8..8b1d751 100644
>>> --- a/src/mga_dri.c
>>> +++ b/src/mga_dri.c
>>> @@ -92,24 +92,24 @@ static Bool MGAInitVisualConfigs( ScreenPtr pScreen )
>>>     case 16:
>>>        numConfigs = 8;
>>>  
>>> -      pConfigs = (__GLXvisualConfig*)xcalloc( sizeof(__GLXvisualConfig),
>>> +      pConfigs = (__GLXvisualConfig*)calloc( 1, sizeof(__GLXvisualConfig) *
>>>  						numConfigs );  
>>
>> Why?  I think the correct thing is the switch numConfigs and sizeof(...)
>> in all these cases.  Calling calloc like that is just silly.
> 
> That's the way I saw the wrapper do it in /usr/include/xorg/os.h:
> 
> #define xcalloc(_num, _size) Xcalloc((unsigned long)(_num)*(unsigned long)(_size))

Notice that Xcalloc took a single argument, like malloc, not two like calloc.
When calling calloc, call it correctly - it's unlikely that the multiplication
will overflow, but calloc is more likely to catch it if it does than if you do
the multiplication yourself.

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



More information about the xorg-devel mailing list