[Mesa-dev] [PATCH mesa] anv: don't crash on vkDestroyDevice(NULL)
Jason Ekstrand
jason at jlekstrand.net
Thu Jul 26 16:16:10 UTC 2018
On Thu, Jul 26, 2018 at 2:26 AM Eric Engestrom <eric.engestrom at intel.com>
wrote:
> On Thursday, 2018-07-26 02:03:58 -0700, Jason Ekstrand wrote:
> > On Thu, Jul 26, 2018 at 1:50 AM Eric Engestrom <eric.engestrom at intel.com
> >
> > wrote:
> >
> > > On Wednesday, 2018-07-25 14:00:29 -0700, Dylan Baker wrote:
> > > > Quoting Eric Engestrom (2018-07-25 11:45:56)
> > > > > CovID: 1438132
> > > > > Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
> > > > > ---
> > > > > src/intel/vulkan/anv_device.c | 4 +++-
> > > > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/src/intel/vulkan/anv_device.c
> > > b/src/intel/vulkan/anv_device.c
> > > > > index 04fd6a829ed60081abc4..3664f80c24dc34955196 100644
> > > > > --- a/src/intel/vulkan/anv_device.c
> > > > > +++ b/src/intel/vulkan/anv_device.c
> > > > > @@ -1832,11 +1832,13 @@ void anv_DestroyDevice(
> > > > > const VkAllocationCallbacks* pAllocator)
> > > > > {
> > > > > ANV_FROM_HANDLE(anv_device, device, _device);
> > > > > - struct anv_physical_device *physical_device =
> > > &device->instance->physicalDevice;
> > > > > + struct anv_physical_device *physical_device;
> > > >
> > > > Is there a particular reason to create the pointer her but assign it
> > > after the
> > > > null check rather than just move the null check between the
> > > ANV_FROM_HANDLE and
> > > > the anv_pysical_device?
> > >
> > > Just the habit of always putting variable declarations before any logic
> > > ¯\_(ツ)_/¯
> > > I thought that was considered best-practice; has that changed?
> > >
> >
> > Yup; welcome to C99. :-)
>
> Haha, I know it's now allowed, but I thought best practice was to still
> keep things grouped, except when there's a reason to have a declaration
> in the middle of the logic.
>
> Looking at the rest of the file, I see a bunch of examples of logic and
> declarations interleaved, so I guess that rule doesn't apply in anv at
> least; guess I'll change my style to match :)
>
Yeah, I (and I think quite a few other people) prefer variables to be as
short-lived as possible. Mixing declarations to achieve that is something
we do at least in all the Intel and NIR code. Separation was required for
a while in core code because of VMWare's use of MSVC but now that they've
moved on to a MSVC version that has a competent C compiler, I think mixing
is allowed there too.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180726/7968bdf2/attachment.html>
More information about the mesa-dev
mailing list