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

Re: [Xen-devel] [RFC 3/6] Introduce _xrealloc



On Thu, Jun 08, 2017 at 08:49:01PM +0100, Julien Grall wrote:
> CC the REST maintainers
> 
> On 08/06/2017 20:30, Sameer Goel wrote:
> > Introduce a memory realloc function.
> > 
> > Signed-off-by: Sameer Goel <sgoel@xxxxxxxxxxxxxx>
> > ---
> >  xen/common/xmalloc_tlsf.c | 13 +++++++++++++
> >  xen/include/xen/xmalloc.h |  1 +
> >  2 files changed, 14 insertions(+)
> > 
> > diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
> > index b256dc5..52385a8 100644
> > --- a/xen/common/xmalloc_tlsf.c
> > +++ b/xen/common/xmalloc_tlsf.c
> > @@ -612,6 +612,19 @@ void *_xzalloc(unsigned long size, unsigned long align)
> >      return p ? memset(p, 0, size) : p;
> >  }
> > 
> > +void *_xrealloc(void *p, unsigned long new_size, unsigned long align)
> > +{
> > +    void *new_p = _xmalloc(new_size, align);
> > +
> > +    if(new_p && p)
> 
> Coding style: if ( ... )
> 
> > +    {
> > +        memcpy(new_p, p, new_size);

This is wrong. How can you know if the area pointed to by p is at least
new_size bytes long?

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.