Skip to content

Commit

Permalink
Replace most uses of assert by ovs_assert.
Browse files Browse the repository at this point in the history
This is a straight search-and-replace, except that I also removed #include
<assert.h> from each file where there were no assert calls left.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Ethan Jackson <[email protected]>
  • Loading branch information
blp committed Jan 17, 2013
1 parent 4749f73 commit cb22974
Show file tree
Hide file tree
Showing 85 changed files with 393 additions and 545 deletions.
6 changes: 2 additions & 4 deletions lib/aes128.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 Nicira, Inc.
* Copyright (c) 2009, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,8 +26,6 @@

#include "aes128.h"

#include <assert.h>

#include "util.h"

static const uint32_t Te0[256] = {
Expand Down Expand Up @@ -748,7 +746,7 @@ aes128_schedule(struct aes128 *aes, const uint8_t key[16])
rk[6] = rk[2] ^ rk[5];
rk[7] = rk[3] ^ rk[6];
}
assert(rk == &aes->rk[40]);
ovs_assert(rk == &aes->rk[40]);
}

void
Expand Down
4 changes: 2 additions & 2 deletions lib/bond.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bond_compose_learning_packet(struct bond *bond,
tag_type tags = 0;
struct flow flow;

assert(may_send_learning_packets(bond));
ovs_assert(may_send_learning_packets(bond));

memset(&flow, 0, sizeof flow);
memcpy(flow.dl_src, eth_src, ETH_ADDR_LEN);
Expand Down Expand Up @@ -1373,7 +1373,7 @@ bond_hash_tcp(const struct flow *flow, uint16_t vlan, uint32_t basis)
static unsigned int
bond_hash(const struct bond *bond, const struct flow *flow, uint16_t vlan)
{
assert(bond->balance == BM_TCP || bond->balance == BM_SLB);
ovs_assert(bond->balance == BM_TCP || bond->balance == BM_SLB);

return (bond->balance == BM_TCP
? bond_hash_tcp(flow, vlan, bond->basis)
Expand Down
15 changes: 7 additions & 8 deletions lib/byteq.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2009 Nicira, Inc.
/* Copyright (c) 2008, 2009, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@

#include <config.h>
#include "byteq.h"
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -65,7 +64,7 @@ byteq_is_full(const struct byteq *q)
void
byteq_put(struct byteq *q, uint8_t c)
{
assert(!byteq_is_full(q));
ovs_assert(!byteq_is_full(q));
*byteq_head(q) = c;
q->head++;
}
Expand All @@ -76,7 +75,7 @@ void
byteq_putn(struct byteq *q, const void *p_, size_t n)
{
const uint8_t *p = p_;
assert(byteq_avail(q) >= n);
ovs_assert(byteq_avail(q) >= n);
while (n > 0) {
size_t chunk = MIN(n, byteq_headroom(q));
memcpy(byteq_head(q), p, chunk);
Expand All @@ -100,7 +99,7 @@ uint8_t
byteq_get(struct byteq *q)
{
uint8_t c;
assert(!byteq_is_empty(q));
ovs_assert(!byteq_is_empty(q));
c = *byteq_tail(q);
q->tail++;
return c;
Expand All @@ -117,7 +116,7 @@ byteq_write(struct byteq *q, int fd)
if (n > 0) {
byteq_advance_tail(q, n);
} else {
assert(n < 0);
ovs_assert(n < 0);
return errno;
}
}
Expand Down Expand Up @@ -165,7 +164,7 @@ byteq_tail(const struct byteq *q)
void
byteq_advance_tail(struct byteq *q, unsigned int n)
{
assert(byteq_tailroom(q) >= n);
ovs_assert(byteq_tailroom(q) >= n);
q->tail += n;
}

Expand All @@ -192,6 +191,6 @@ byteq_headroom(const struct byteq *q)
void
byteq_advance_head(struct byteq *q, unsigned int n)
{
assert(byteq_headroom(q) >= n);
ovs_assert(byteq_headroom(q) >= n);
q->head += n;
}
7 changes: 3 additions & 4 deletions lib/cfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <config.h>
#include "cfm.h"

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -190,7 +189,7 @@ cfm_generate_maid(struct cfm *cfm)
md_len = strlen(ovs_md_name);
ma_len = strlen(ovs_ma_name);

assert(md_len && ma_len && md_len + ma_len + 4 <= CCM_MAID_LEN);
ovs_assert(md_len && ma_len && md_len + ma_len + 4 <= CCM_MAID_LEN);

cfm->maid[0] = 4; /* MD name string format. */
cfm->maid[1] = md_len; /* MD name size. */
Expand Down Expand Up @@ -368,7 +367,7 @@ cfm_run(struct cfm *cfm)
cfm->health = (rmp->num_health_ccm * 100) / exp_ccm_recvd;
cfm->health = MIN(cfm->health, 100);
rmp->num_health_ccm = 0;
assert(cfm->health >= 0 && cfm->health <= 100);
ovs_assert(cfm->health >= 0 && cfm->health <= 100);
}
cfm->health_interval = 0;
}
Expand Down Expand Up @@ -466,7 +465,7 @@ cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
}

if (cfm->ccm_interval == 0) {
assert(cfm->extended);
ovs_assert(cfm->extended);
ccm->interval_ms_x = htons(cfm->ccm_interval_ms);
} else {
ccm->interval_ms_x = htons(0);
Expand Down
3 changes: 1 addition & 2 deletions lib/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <config.h>
#include "classifier.h"
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include "byte-order.h"
Expand Down Expand Up @@ -208,7 +207,7 @@ void
classifier_insert(struct classifier *cls, struct cls_rule *rule)
{
struct cls_rule *displaced_rule = classifier_replace(cls, rule);
assert(!displaced_rule);
ovs_assert(!displaced_rule);
}

/* Removes 'rule' from 'cls'. It is the caller's responsibility to destroy
Expand Down
5 changes: 3 additions & 2 deletions lib/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <config.h>
#include "daemon.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
Expand Down Expand Up @@ -158,7 +157,9 @@ daemon_set_monitor(void)
void
daemon_save_fd(int fd)
{
assert(fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO);
ovs_assert(fd == STDIN_FILENO ||
fd == STDOUT_FILENO ||
fd == STDERR_FILENO);
save_fds[fd] = true;
}

Expand Down
15 changes: 7 additions & 8 deletions lib/dpif-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "dpif-linux.h"

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -958,7 +957,7 @@ dpif_linux_operate__(struct dpif *dpif_, struct dpif_op **ops, size_t n_ops)
struct nl_transaction *txnsp[MAX_OPS];
size_t i;

assert(n_ops <= MAX_OPS);
ovs_assert(n_ops <= MAX_OPS);
for (i = 0; i < n_ops; i++) {
struct op_auxdata *aux = &auxes[i];
struct dpif_op *op = ops[i];
Expand Down Expand Up @@ -1579,7 +1578,7 @@ dpif_linux_vport_transact(const struct dpif_linux_vport *request,
struct ofpbuf *request_buf;
int error;

assert((reply != NULL) == (bufp != NULL));
ovs_assert((reply != NULL) == (bufp != NULL));

error = dpif_linux_init();
if (error) {
Expand Down Expand Up @@ -1730,7 +1729,7 @@ dpif_linux_dp_transact(const struct dpif_linux_dp *request,
struct ofpbuf *request_buf;
int error;

assert((reply != NULL) == (bufp != NULL));
ovs_assert((reply != NULL) == (bufp != NULL));

request_buf = ofpbuf_new(1024);
dpif_linux_dp_to_ofpbuf(request, request_buf);
Expand Down Expand Up @@ -1851,9 +1850,9 @@ dpif_linux_flow_to_ofpbuf(const struct dpif_linux_flow *flow,
}

/* We never need to send these to the kernel. */
assert(!flow->stats);
assert(!flow->tcp_flags);
assert(!flow->used);
ovs_assert(!flow->stats);
ovs_assert(!flow->tcp_flags);
ovs_assert(!flow->used);

if (flow->clear) {
nl_msg_put_flag(buf, OVS_FLOW_ATTR_CLEAR);
Expand All @@ -1880,7 +1879,7 @@ dpif_linux_flow_transact(struct dpif_linux_flow *request,
struct ofpbuf *request_buf;
int error;

assert((reply != NULL) == (bufp != NULL));
ovs_assert((reply != NULL) == (bufp != NULL));

if (reply) {
request->nlmsg_flags |= NLM_F_ECHO;
Expand Down
7 changes: 3 additions & 4 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <config.h>
#include "dpif.h"

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -160,7 +159,7 @@ static void dp_netdev_execute_actions(struct dp_netdev *,
static struct dpif_netdev *
dpif_netdev_cast(const struct dpif *dpif)
{
assert(dpif->dpif_class->open == dpif_netdev_open);
ovs_assert(dpif->dpif_class->open == dpif_netdev_open);
return CONTAINER_OF(dpif, struct dpif_netdev, dpif);
}

Expand Down Expand Up @@ -289,7 +288,7 @@ dpif_netdev_open(const struct dpif_class *class, const char *name,
if (error) {
return error;
}
assert(dp != NULL);
ovs_assert(dp != NULL);
}
} else {
if (dp->class != class) {
Expand Down Expand Up @@ -337,7 +336,7 @@ static void
dpif_netdev_close(struct dpif *dpif)
{
struct dp_netdev *dp = get_dp_netdev(dpif);
assert(dp->open_cnt > 0);
ovs_assert(dp->open_cnt > 0);
if (--dp->open_cnt == 0 && dp->destroyed) {
shash_find_and_delete(&dp_netdevs, dp->name);
dp_netdev_free(dp);
Expand Down
3 changes: 1 addition & 2 deletions lib/dpif-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* exposed over OpenFlow as a single switch. Datapaths and the collections of
* ports that they contain may be fixed or dynamic. */

#include <assert.h>
#include "openflow/openflow.h"
#include "dpif.h"
#include "util.h"
Expand All @@ -49,7 +48,7 @@ void dpif_uninit(struct dpif *dpif, bool close);
static inline void dpif_assert_class(const struct dpif *dpif,
const struct dpif_class *dpif_class)
{
assert(dpif->dpif_class == dpif_class);
ovs_assert(dpif->dpif_class == dpif_class);
}

/* Datapath interface class structure, to be defined by each implementation of
Expand Down
13 changes: 6 additions & 7 deletions lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <config.h>
#include "dpif-provider.h"

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
Expand Down Expand Up @@ -265,7 +264,7 @@ do_open(const char *name, const char *type, bool create, struct dpif **dpifp)
error = registered_class->dpif_class->open(registered_class->dpif_class,
name, create, &dpif);
if (!error) {
assert(dpif->dpif_class == registered_class->dpif_class);
ovs_assert(dpif->dpif_class == registered_class->dpif_class);
registered_class->refcount++;
}

Expand Down Expand Up @@ -329,8 +328,8 @@ dpif_close(struct dpif *dpif)

registered_class = shash_find_data(&dpif_classes,
dpif->dpif_class->type);
assert(registered_class);
assert(registered_class->refcount);
ovs_assert(registered_class);
ovs_assert(registered_class->refcount);

registered_class->refcount--;
dpif_uninit(dpif, true);
Expand Down Expand Up @@ -614,7 +613,7 @@ dpif_port_get_name(struct dpif *dpif, uint32_t port_no,
struct dpif_port port;
int error;

assert(name_size > 0);
ovs_assert(name_size > 0);

error = dpif_port_query_by_number(dpif, port_no, &port);
if (!error) {
Expand Down Expand Up @@ -821,8 +820,8 @@ dpif_flow_put__(struct dpif *dpif, const struct dpif_flow_put *put)
int error;

COVERAGE_INC(dpif_flow_put);
assert(!(put->flags & ~(DPIF_FP_CREATE | DPIF_FP_MODIFY
| DPIF_FP_ZERO_STATS)));
ovs_assert(!(put->flags & ~(DPIF_FP_CREATE | DPIF_FP_MODIFY
| DPIF_FP_ZERO_STATS)));

error = dpif->dpif_class->flow_put(dpif, put);
if (error && put->stats) {
Expand Down
3 changes: 1 addition & 2 deletions lib/dynamic-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <config.h>
#include "dynamic-string.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
Expand Down Expand Up @@ -165,7 +164,7 @@ ds_put_format_valist(struct ds *ds, const char *format, va_list args_)
needed = vsnprintf(&ds->string[ds->length], available, format, args);
va_end(args);

assert(needed < available);
ovs_assert(needed < available);
ds->length += needed;
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/fatal-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
#include <config.h>
#include "fatal-signal.h"
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
Expand Down Expand Up @@ -112,7 +111,7 @@ fatal_signal_add_hook(void (*hook_cb)(void *aux), void (*cancel_cb)(void *aux),
{
fatal_signal_init();

assert(n_hooks < MAX_HOOKS);
ovs_assert(n_hooks < MAX_HOOKS);
hooks[n_hooks].hook_cb = hook_cb;
hooks[n_hooks].cancel_cb = cancel_cb;
hooks[n_hooks].aux = aux;
Expand Down
3 changes: 1 addition & 2 deletions lib/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <config.h>
#include <sys/types.h>
#include "flow.h"
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
Expand Down Expand Up @@ -347,7 +346,7 @@ flow_extract(struct ofpbuf *packet, uint32_t skb_priority, uint32_t skb_mark,
memset(flow, 0, sizeof *flow);

if (tnl) {
assert(tnl != &flow->tunnel);
ovs_assert(tnl != &flow->tunnel);
flow->tunnel = *tnl;
}
flow->in_port = ofp_in_port;
Expand Down
Loading

0 comments on commit cb22974

Please sign in to comment.