This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Checking xmalloc's return status in c-pragma.c


  In message <199910271401.PAA03856@pathia.cygnus.co.uk>you write:
  > Hi David,
  > 
  > : 1999-10-26  David Starner  <dstarner98@aasaa.ofe.org>
  > : 
  > :         * c-pragma.c (push_alignment): Don't check the return value
  > :         of xmalloc.
  > 
  > : push_alignment in c-pragma.c checks xmalloc's return status to
  > : see if there was enough memory to allocate something. Unfortunetly,
  > : if I'm not mistaken, xmalloc doesn't return if there wasn't enough
  > : memory.
  > 
  > Whilst this is true, I do not really see the benefit in deleting this
  > code.  The check is not going to take a lot of resources to compute,
  > and it is a good example of paranoid programming.  Just because
  > xmalloc() currently will not return NULL, this does not mean that in
  > the future it may be re-implemented so that it can return NULL, or
  > maybe a bug might be introduced that causes it to return NULL.
But the whole point of xmalloc is it provides a front-end to malloc that
does two things.

  1. Correctly handles malloc (0)
  2. Always checks the return value and halts the program it malloc failed.

That is the entire purpose of xmalloc.  It is not going to be changed to
return null.  Ever.

jeff
  > 
  > The check does not harm, does not slow down the compiler and might
  > catch future bugs.  I would say leave the check in.
  > 
  > Cheers
  > 	Nick
  > 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]