[Snort-devel] Bug : misuse of calloc (patch included)

Marc Norton marc.norton at ...402...
Thu Jul 29 11:07:13 EDT 2004


Our experience has shown this to be a non-issue, even with Solaris/sun
based systems, which can be pretty fussy.  I appreciate the diligence
your applying in going through the code, but this is a non-issue for the
reasons Gisle has cited.

> -----Original Message-----
> From: snort-devel-admin at lists.sourceforge.net [mailto:snort-devel-
> admin at lists.sourceforge.net] On Behalf Of Gisle Vanem
> Sent: Thursday, July 29, 2004 2:48 AM
> To: snort-devel at lists.sourceforge.net
> Subject: Re: [Snort-devel] Bug : misuse of calloc (patch included)
> 
> "Erik de Castro Lopo" said:
> 
> > which is asking for a pointer to sizeof(SOME_STRUCT) elements
> > of size one. As such, it is legal for the allocator to return
> > a pointer without worrying about alignment at all. Then, if
> > the struct contains say an int32_t, the int32_t may not be
> > aligned to a four byte boundary which on some architectures
> > can cause a bus fault.
> 
> Hm, I've always thought it was the responsibility of the compiler
> and person using it, to care about alignment. How can calloc() know
> the layout of what struct you're asking for? Besides, on those
problematic
> platforms, wouldn't every allocation be a multiple of ALIGN (normally
8)?
> 
> >  void * mwmNew()
> >  {
> > -   MWM_STRUCT * p = (MWM_STRUCT * )calloc( sizeof(MWM_STRUCT),1 );
> > +   MWM_STRUCT * p = (MWM_STRUCT * )calloc( 1, sizeof(MWM_STRUCT) );
> 
> Isn't this much simpler:
>   MWM_STRUCT * p = calloc(sizeof(*p), 1);
> 
> And why cast a 'void *' from calloc()? This is C, not C++ right?
> 
> --gv
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by BEA Weblogic Workshop
> FREE Java Enterprise J2EE developer tools!
> Get your free copy of BEA WebLogic Workshop 8.1 today.
> http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
> _______________________________________________
> Snort-devel mailing list
> Snort-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/snort-devel






More information about the Snort-devel mailing list