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

Re: why is this code here?

On Fri, Dec 10, 1999 at 02:11:36PM -0800, Sean 'Shaleh' Perry was heard to say:
> >> preventry is set to NULL at the top, strdup("") just sets it to NULL again. 
> >> What am I missing????
> > 
> >   Huh?  Unless the semantics of C strings have changed underneath me,
> > strdup("")
> > sets it to *a pointer to* a NULL byte.  This is important, since otherwise
> > you'll segfault when you try to access strdup..assuming that inputBox doesn't
> > treat NULL strings as "".
> > 
> assuming that inputbox really won't read NULL, why not simply do 'preventry =
> "";'???

  I think because the code then free()s preventry, and trying to remember
whether we should free it or not would be much harder (for the coder :) ) than
just strduping "".


The only thing worse than infinite recursion is infinite recursion.

Reply to: