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



On Thu, 5 Jan 2006, Rodrigo Moya wrote:

On Thu, 2006-01-05 at 18:43 +0800, James Henstridge wrote:
Rodrigo Moya wrote:

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)


hmm, but if I understand it correctly, this would yield an invalid value
when n_args = 0, since it would be:

sizeof (GtkBindingSignal) + 0 * sizeof (GtkBindingArg) - sizeof
(GtkBindingArg)

which will be:

sizeof (GtkBindingSignal) + sizeof (GtkBindingArg)


It would actually be:
    sizeof (GtkBindingSignal) - sizeof (GtkBindingArg)

yes, sorry, mistyped it.

is that what we want?


Yes.  That allocates enough space for everything except the 1-element
GtkBindingArg array at the end of the structure, which is not a problem
if n_args is 0.

ok, patch attached

-  signal = (GtkBindingSignal *) g_slice_alloc0 (sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg));
+  signal = (GtkBindingSignal *) g_slice_alloc0 (sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg) - sizeof (GtkBindingArg));

thanks, rodrigo, please apply.

--
Rodrigo Moya <rodrigo gnome-db org>


---
ciaoTJ



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