misc: Use g_assert_not_reached for code which is expected to be unreachable
PATCH 1/1 misc: Use g_assert_not_reached for code which is expected to be unreachable
The macro g_assert_not_reached is a better self documenting replacement for assert(0) or assert(false).
Signed-off-by Stefan Weil <[email protected]>
---
The patch replaces [g_]assert(0), [g_]assert(false) by g_assert_not_reached().
It did not remove some code like assignments, break or return statements after the g_assert_not_reached statement.
Up to now, my compilers did not complain, but this might need an additional fix in the future.
Stefan
blockdev.c | 2 +- hw/net/vmxnet3.c | 16 ++++++++-------- hw/net/vmxnet_tx_pkt.c | 2 +- hw/usb/hcd-ehci.c | 8 ++++---- net/eth.c | 2 +- qdev-monitor.c | 4 ++-- target-arm/helper.c | 2 +- tests/test-qmp-input-visitor.c | 2 +- tests/test-qmp-output-visitor.c | 4 ++-- tests/test-visitor-serialization.c | 8 ++++---- 10 files changed, 25 insertions(+), 25 deletions(-)
blockdev.c +1 -1
@@ -971,7 +971,7 @@ static void abort_prepare(BlkTransactionState *common, Error **errp)static void abort_commit (BlkTransactionState *common) { -assert (false);/* this action never succeeds */ +g_assert_not_reached ();/* this action never succeeds */ }static const BdrvActionOps actions[] = {
hw/net/vmxnet3.c +8 -8
@@ -528,7 +528,7 @@ vmxnet3_setup_tx_offloads(VMXNET3State *s)break ;default : -assert (false); +g_assert_not_reached ();return false; }
@@ -575,7 +575,7 @@ vmxnet3_on_tx_done_update_stats(VMXNET3State *s, int qidx, stats->ucastBytesTxOK += tot_len;break ;default : -assert (false); +g_assert_not_reached (); }if (s->offload_mode ==VMXNET3_OM_TSO ) {
@@ -599,7 +599,7 @@ vmxnet3_on_tx_done_update_stats(VMXNET3State *s, int qidx,break ;default : -assert (false); +g_assert_not_reached (); } }
@@ -634,7 +634,7 @@ vmxnet3_on_rx_done_update_stats(VMXNET3State *s, stats->ucastBytesRxOK += tot_len;break ;default : -assert (false); +g_assert_not_reached (); }if (tot_len > s->mtu) {
@@ -643,7 +643,7 @@ vmxnet3_on_rx_done_update_stats(VMXNET3State *s, }break ;default : -assert (false); +g_assert_not_reached (); } }
@@ -1106,7 +1106,7 @@ vmxnet3_io_bar0_read(void *opaque, hwaddr addr, unsigned size) {if (VMW_IS_MULTIREG_ADDR (addr,VMXNET3_REG_IMR ,VMXNET3_MAX_INTRS ,VMXNET3_REG_ALIGN )) { -assert (false); +g_assert_not_reached (); }VMW_CBPRN ("BAR0 unknown read [%" PRIx64"], size %d" , addr, size);
@@ -1651,7 +1651,7 @@ vmxnet3_io_bar1_write(void *opaque,case VMXNET3_REG_ICR :VMW_CBPRN ("Write BAR1 [VMXNET3_REG_ICR] = %" PRIx64", size %d" , val, size); -assert (false); +g_assert_not_reached ();break ;/* Event Cause Register */
@@ -1801,7 +1801,7 @@ vmxnet3_rx_filter_may_indicate(VMXNET3State *s, const void *data,break ;default : -assert (false); +g_assert_not_reached (); }return true;
hw/net/vmxnet_tx_pkt.c +1 -1
@@ -287,7 +287,7 @@ void vmxnet_tx_pkt_build_vheader(struct VmxnetTxPkt *pkt, bool tso_enable,break ;default : -assert (false); +g_assert_not_reached (); }if (csum_enable) {
hw/usb/hcd-ehci.c +4 -4
@@ -1357,7 +1357,7 @@ static void ehci_execute_complete(EHCIQueue *q)default :/* should not be triggerable */ fprintf (stderr,"USB invalid response %d\n" , p->packet.status); -assert (0 ); +g_assert_not_reached ();break ; }
@@ -2142,7 +2142,7 @@ static void ehci_advance_state(EHCIState *ehci, int async)default :fprintf (stderr,"Bad state!\n" ); again =-1 ; -assert (0 ); +g_assert_not_reached ();break ; }
@@ -2206,7 +2206,7 @@ static void ehci_advance_async_state(EHCIState *ehci)/* this should only be due to a developer mistake */ fprintf (stderr,"ehci: Bad asynchronous state %d. " "Resetting to active\n" , ehci->astate); -assert (0 ); +g_assert_not_reached (); } }
@@ -2256,7 +2256,7 @@ static void ehci_advance_periodic_state(EHCIState *ehci)/* this should only be due to a developer mistake */ fprintf (stderr,"ehci: Bad periodic state %d. " "Resetting to active\n" , ehci->pstate); -assert (0 ); +g_assert_not_reached (); } }
net/eth.c +1 -1
@@ -73,7 +73,7 @@ eth_get_gso_type(uint16_t l3_proto, uint8_t *l3_hdr, uint8_t l4proto) }/* Unsupported offload */ -assert (false); +g_assert_not_reached ();return VIRTIO_NET_HDR_GSO_NONE | ecn_state; }
qdev-monitor.c +2 -2
@@ -360,7 +360,7 @@ static BusState *qbus_find(const char *path)/* find device */ if (sscanf (path+pos,"%127[^/]%n" , elem, &len) !=1 ) { -assert (0 ); +g_assert_not_reached (); elem[0 ] = len =0 ; } pos += len;
@@ -397,7 +397,7 @@ static BusState *qbus_find(const char *path)/* find bus */ if (sscanf (path+pos,"%127[^/]%n" , elem, &len) !=1 ) { -assert (0 ); +g_assert_not_reached (); elem[0 ] = len =0 ; } pos += len;
target-arm/helper.c +1 -1
@@ -1653,7 +1653,7 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,"was %s, now %s\n" , r2->cp,32 +32 * is64, r2->crn, r2->crm, r2->opc1, r2->opc2, oldreg->name, r2->name); -assert (0 ); +g_assert_not_reached (); } }g_hash_table_insert (cpu->cp_regs, key, r2);
tests/test-qmp-input-visitor.c +1 -1
@@ -394,7 +394,7 @@ static void test_native_list_integer_helper(TestInputVisitorData *data,break ; }default : -g_assert (false); +g_assert_not_reached (); }g_string_free (gstr_union, true);
tests/test-qmp-output-visitor.c +2 -2
@@ -559,7 +559,7 @@ static void init_native_list(UserDefNativeListUnion *cvalue)break ; }default : -g_assert (false); +g_assert_not_reached (); } }
@@ -645,7 +645,7 @@ static void check_native_list(QObject *qobj, }break ;default : -g_assert (false); +g_assert_not_reached (); }QDECREF (qlist); }
tests/test-visitor-serialization.c +4 -4
@@ -136,7 +136,7 @@ static void visit_primitive_type(Visitor *v, void **native, Error **errp)visit_type_int64 (v, &pt->value.s64,NULL , errp);break ;case PTYPE_EOL : -g_assert (false); +g_assert_not_reached (); } }
@@ -181,7 +181,7 @@ static void visit_primitive_list(Visitor *v, void **native, Error **errp)visit_type_uint64List (v, &pl->value.u64_integers,NULL , errp);break ;default : -g_assert (false); +g_assert_not_reached (); } }
@@ -500,7 +500,7 @@ static void test_primitive_lists(gconstpointer opaque)break ; }default : -g_assert (0 ); +g_assert_not_reached (); } }
@@ -656,7 +656,7 @@ static void test_primitive_lists(gconstpointer opaque)break ; }default : -g_assert (0 ); +g_assert_not_reached (); } i++; }while (cur_head);
Signature · 1 line
1.7.10.4
Michael Tokarev
AppliedQuoted 2 lines · Stefan Weil
The macro
g_assert_not_reachedis a better self documenting replacement for assert(0) or assert(false).
Thanks, applied to the trivial patches queue.
/mjt