Re: [PATCH] Don't multiply by -1 when assigning memory



Rodrigo Moya wrote:

>On Wed, 2006-01-04 at 07:34 -0500, Matthias Clasen wrote:
>  
>
>>On Wed, 2006-01-04 at 13:18 +0100, Rodrigo Moya wrote:
>>    
>>
>>>Hi
>>>
>>>Attached patch fixes a problem I just found out. Running any GTK app
>>>showed this:
>>>
>>>GLib-ERROR **: gmem.c:143: failed to allocate 68719477360 bytes
>>>
>>>I found the culprit to be the patched function, which was multiplying by
>>>-1 when n_args was 0.
>>>
>>>Ok to commit to HEAD?
>>>      
>>>
>>No, thats not the right fix. We do want to subtract one GtkBindingArg
>>size from the GtkBindingSignal size there. 
>>
>>    
>>
>that's what it does for all cases, except when it is 0.
>  
>
What Matthias is saying is that in the case of zero args, you don't need
to allocate the full size of GtkBindingSignal: you don't need to
GtkBindingArg embedded at the end of the struct.  So the correct answer
would probably be:
  sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg) - sizeof
(GtkBindingArg)

(which should gives a different answer to the current code due to
unsigned arithmetic).

James.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]