[MPlayer-cvslog] r33008 - trunk/gui/app.c

Reimar Döffinger Reimar.Doeffinger at gmx.de
Fri Mar 4 20:19:02 CET 2011


On Thu, Mar 03, 2011 at 09:55:39PM +0100, Ingo Brückl wrote:
> Reimar Döffinger wrote on Thu, 3 Mar 2011 21:46:32 +0100:
> 
> > On Thu, Mar 03, 2011 at 12:43:01PM +0100, ib wrote:
> >>  static void appClearItem(wItem *item)
> >>  {
> >> -    item->type    = 0;
> >> +    item->type   = itNone;
> >>      item->x       = 0;
> >>      item->y       = 0;
> >>      item->width   = 0;
> >>      item->height  = 0;
> >> -    item->pwidth  = 0;
> >> -    item->pheight = 0;
> >> -    item->message = 0;
> >> -    item->pressed = btnReleased;
> >> -    item->tmp     = 0;
> >>      bpFree(&item->Bitmap);
> >> +    bpFree(&item->Mask);
> >>      item->fontid = 0;
> >> -    free(item->label);
> >> -    item->label = NULL;
> >> -    free(item->text);
> >> -    item->text      = NULL;
> >> +    item->align  = fntAlignLeft;
> >> +    gfree((void **)&item->label);
> >> +    item->pwidth    = 0;
> >> +    item->pheight   = 0;
> >> +    item->numphases = 0;
> >> +    item->value     = 0;
> >> +    item->message   = evNone;
> >> +    item->R = 0;
> >> +    item->G = 0;
> >> +    item->B = 0;
> >> +    gfree((void **)&item->text);
> >>      item->textwidth = 0;
> >>      item->starttime = 0;
> >>      item->last_x    = 0;
> >> +    item->pressed   = btnDisabled;
> >> +    item->tmp       = 0;
> 
> > It would be nicer to memset to 0 first to get rid of most of
> > those assignments. Also avoids forgetting to initialize
> > when you ever add a new field.
> 
> There is another structure within the wItem structure. I cannot memset wItem,
> because I don't know whether this is the right way for this other structure
> (which is handled by bpFree()). This is why I decided against a memset here.

Freeing is handled by that, so you of course call it first.
After that you can do a memset and it's at the same state as initially.
If some special initialization is needed, that should be done in a init
function after that, it has no place in a function called bpFree.
Though the bpFree function does just free a sub-element and then memset...


More information about the MPlayer-cvslog mailing list