diff mbox series

[11/15] libxl_usb: Fix wrong usage of asserts

Message ID 20190614112444.29980-12-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show
Series Some cleanup of libxl | expand

Commit Message

Anthony PERARD June 14, 2019, 11:24 a.m. UTC
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libxl/libxl_usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ian Jackson Sept. 17, 2019, 4:44 p.m. UTC | #1
Anthony PERARD writes ("[PATCH 11/15] libxl_usb: Fix wrong usage of asserts"):
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

I'm not sure why you wouldn't just delete the breaks, rather than
replacing them "return" ?

Thanks,
Ian.
Anthony PERARD Sept. 18, 2019, 10:17 a.m. UTC | #2
On Tue, Sep 17, 2019 at 05:44:03PM +0100, Ian Jackson wrote:
> Anthony PERARD writes ("[PATCH 11/15] libxl_usb: Fix wrong usage of asserts"):
> > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> 
> I'm not sure why you wouldn't just delete the breaks, rather than
> replacing them "return" ?

Because asserts aren't supposed to be compiled in a release build. I
know that's not the case in libxl...

I could replace the assert(0) by abort() instead, they won't be need for
a break or return after it.
Ian Jackson Sept. 18, 2019, 10:39 a.m. UTC | #3
Anthony PERARD writes ("Re: [PATCH 11/15] libxl_usb: Fix wrong usage of asserts"):
> On Tue, Sep 17, 2019 at 05:44:03PM +0100, Ian Jackson wrote:
> > Anthony PERARD writes ("[PATCH 11/15] libxl_usb: Fix wrong usage of asserts"):
> > > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> > 
> > I'm not sure why you wouldn't just delete the breaks, rather than
> > replacing them "return" ?
> 
> Because asserts aren't supposed to be compiled in a release build. I
> know that's not the case in libxl...

Oh I see.

> I could replace the assert(0) by abort() instead, they won't be need for
> a break or return after it.

Yes, please.

Ian.
diff mbox series

Patch

diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c
index 3d389c0198..694870a3c3 100644
--- a/tools/libxl/libxl_usb.c
+++ b/tools/libxl/libxl_usb.c
@@ -148,7 +148,7 @@  static int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid,
         break;
     default:
         assert(0); /* can't really happen. */
-        break;
+        return ERROR_INVAL;
     }
     device->devid           = usbctrl->devid;
     device->domid           = domid;
@@ -371,7 +371,7 @@  static int libxl__device_usbctrl_add_hvm(libxl__gc *gc, uint32_t domid,
         break;
     default:
         assert(0); /* Should not be possible. */
-        break;
+        return ERROR_INVAL;
     }
 
     flexarray_append_pair(qmp_args, "id",