qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 4/9] util/oslib-win32: Return NULL on qemu_try_memalign() wit


From: Peter Maydell
Subject: Re: [PATCH 4/9] util/oslib-win32: Return NULL on qemu_try_memalign() with zero size
Date: Fri, 4 Mar 2022 10:20:52 +0000

On Thu, 3 Mar 2022 at 23:02, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 3/3/22 06:55, Peter Maydell wrote:
> >> Alternately, force size == 1, so that we always get a non-NULL value that 
> >> can be freed.
> >> That's a change on the POSIX side as well, of course.
> >
> > Yes, I had a look at what actual malloc() implementations tend
> > to do, and the answer seems to be that forcing size to 1 gives
> > less weird behaviour for the application. So here that would be
> >
> >     if (size == 0) {
> >         size++;
> >     }
> >     ptr = _aligned_malloc(size, alignment);
> >
> > We don't need to do anything on the POSIX side (unless we want to
> > enforce consistency of handling the size==0 case).
>
> I would do this unconditionally.  The POSIX manpage says that either NULL or 
> a unique
> pointer is a valid return value into *memptr here for size == 0.  What we 
> want in our
> caller is NULL if and only if error.

Mm, I guess. I was trying to avoid changing the POSIX-side behaviour,
but this seems safe enough.

-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]