From ebc56baa41db060b8783051e67b6fcbc148ebd60 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 13 Jul 2012 16:00:29 -0700 Subject: [PATCH] util: New macro CONST_CAST. Casts are sometimes necessary. One common reason that they are necessary is for discarding a "const" qualifier. However, this can impede maintenance: if the type of the expression being cast changes, then the presence of the cast can hide a necessary change in the code that does the cast. Using CONST_CAST, instead of a bare cast, makes these changes visible. Inspired by my own work elsewhere: http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80 Signed-off-by: Ben Pfaff --- lib/bitmap.h | 4 ++-- lib/dpif-linux.c | 12 +++++++----- lib/dynamic-string.c | 2 +- lib/hmap.h | 2 +- lib/json.c | 6 +++--- lib/list.c | 6 +++--- lib/netdev-linux.c | 4 ++-- lib/netdev.c | 2 +- lib/netlink-socket.c | 2 +- lib/ofpbuf.c | 4 ++-- lib/ovsdb-data.c | 5 +++-- lib/ovsdb-idl.c | 6 +++--- lib/shash.c | 6 +++--- lib/sset.h | 5 +++-- lib/stp.c | 4 ++-- lib/stream-ssl.c | 4 ++-- lib/util.h | 10 ++++++++++ lib/vlog.c | 2 +- ofproto/connmgr.c | 2 +- ofproto/ofproto-dpif.c | 4 ++-- ofproto/ofproto.c | 2 +- ovsdb/ovsdb-server.c | 8 ++++---- ovsdb/row.c | 6 +++--- ovsdb/transaction.c | 12 ++++++------ tests/test-stp.c | 4 ++-- 25 files changed, 69 insertions(+), 55 deletions(-) diff --git a/lib/bitmap.h b/lib/bitmap.h index 47b77e73..89804962 100644 --- a/lib/bitmap.h +++ b/lib/bitmap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 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. @@ -26,7 +26,7 @@ static inline unsigned long * bitmap_unit__(const unsigned long *bitmap, size_t offset) { - return (unsigned long *) &bitmap[offset / BITMAP_ULONG_BITS]; + return CONST_CAST(unsigned long *, &bitmap[offset / BITMAP_ULONG_BITS]); } static inline unsigned long diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 97850f5b..d9c50ccd 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -595,8 +595,8 @@ dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_, return error; } - dpif_port->name = (char *) vport.name; - dpif_port->type = (char *) netdev_vport_get_netdev_type(&vport); + dpif_port->name = CONST_CAST(char *, vport.name); + dpif_port->type = CONST_CAST(char *, netdev_vport_get_netdev_type(&vport)); dpif_port->port_no = vport.port_no; return 0; } @@ -668,7 +668,7 @@ dpif_linux_flow_get(const struct dpif *dpif_, dpif_linux_flow_get_stats(&reply, stats); } if (actionsp) { - buf->data = (void *) reply.actions; + buf->data = CONST_CAST(struct nlattr *, reply.actions); buf->size = reply.actions_len; *actionsp = buf; } else { @@ -1169,9 +1169,11 @@ parse_odp_packet(struct ofpbuf *buf, struct dpif_upcall *upcall, memset(upcall, 0, sizeof *upcall); upcall->type = type; upcall->packet = buf; - upcall->packet->data = (void *) nl_attr_get(a[OVS_PACKET_ATTR_PACKET]); + upcall->packet->data = CONST_CAST(struct nlattr *, + nl_attr_get(a[OVS_PACKET_ATTR_PACKET])); upcall->packet->size = nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]); - upcall->key = (void *) nl_attr_get(a[OVS_PACKET_ATTR_KEY]); + upcall->key = CONST_CAST(struct nlattr *, + nl_attr_get(a[OVS_PACKET_ATTR_KEY])); upcall->key_len = nl_attr_get_size(a[OVS_PACKET_ATTR_KEY]); upcall->userdata = (a[OVS_PACKET_ATTR_USERDATA] ? nl_attr_get_u64(a[OVS_PACKET_ATTR_USERDATA]) diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c index e7ad73cd..b648eef6 100644 --- a/lib/dynamic-string.c +++ b/lib/dynamic-string.c @@ -311,7 +311,7 @@ ds_cstr(struct ds *ds) const char * ds_cstr_ro(const struct ds *ds) { - return ds_cstr((struct ds *) ds); + return ds_cstr(CONST_CAST(struct ds *, ds)); } /* Returns a null-terminated string representing the current contents of 'ds', diff --git a/lib/hmap.h b/lib/hmap.h index 9d07e842..2867bfa0 100644 --- a/lib/hmap.h +++ b/lib/hmap.h @@ -247,7 +247,7 @@ hmap_next_with_hash__(const struct hmap_node *node, size_t hash) while (node != NULL && node->hash != hash) { node = node->next; } - return (struct hmap_node *) node; + return CONST_CAST(struct hmap_node *, node); } /* Returns the first node in 'hmap' with the given 'hash', or a null pointer if diff --git a/lib/json.c b/lib/json.c index ddce335a..f0b6456a 100644 --- a/lib/json.c +++ b/lib/json.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 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. @@ -296,14 +296,14 @@ struct json_array * json_array(const struct json *json) { assert(json->type == JSON_ARRAY); - return (struct json_array *) &json->u.array; + return CONST_CAST(struct json_array *, &json->u.array); } struct shash * json_object(const struct json *json) { assert(json->type == JSON_OBJECT); - return (struct shash *) json->u.object; + return CONST_CAST(struct shash *, json->u.object); } bool diff --git a/lib/list.c b/lib/list.c index 71790cc3..804a7e56 100644 --- a/lib/list.c +++ b/lib/list.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 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. @@ -136,7 +136,7 @@ list_pop_back(struct list *list) struct list * list_front(const struct list *list_) { - struct list *list = (struct list *) list_; + struct list *list = CONST_CAST(struct list *, list_); assert(!list_is_empty(list)); return list->next; @@ -147,7 +147,7 @@ list_front(const struct list *list_) struct list * list_back(const struct list *list_) { - struct list *list = (struct list *) list_; + struct list *list = CONST_CAST(struct list *, list_); assert(!list_is_empty(list)); return list->prev; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index efce9a7e..412a92de 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -955,7 +955,7 @@ netdev_linux_send(struct netdev *netdev_, const void *data, size_t size) sll.sll_family = AF_PACKET; sll.sll_ifindex = ifindex; - iov.iov_base = (void *) data; + iov.iov_base = CONST_CAST(void *, data); iov.iov_len = size; msg.msg_name = &sll; @@ -4106,7 +4106,7 @@ tc_query_qdisc(const struct netdev *netdev) } /* Instantiate it. */ - load_error = ops->tc_load((struct netdev *) netdev, qdisc); + load_error = ops->tc_load(CONST_CAST(struct netdev *, netdev), qdisc); assert((load_error == 0) == (netdev_dev->tc != NULL)); ofpbuf_delete(qdisc); diff --git a/lib/netdev.c b/lib/netdev.c index ac98cb52..394d8957 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -847,7 +847,7 @@ do_update_flags(struct netdev *netdev, enum netdev_flags off, int netdev_get_flags(const struct netdev *netdev_, enum netdev_flags *flagsp) { - struct netdev *netdev = (struct netdev *) netdev_; + struct netdev *netdev = CONST_CAST(struct netdev *, netdev_); return do_update_flags(netdev, 0, 0, flagsp, false); } diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 3bdbbd73..49a8493e 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -683,7 +683,7 @@ nl_sock_transact(struct nl_sock *sock, const struct ofpbuf *request, struct nl_transaction *transactionp; struct nl_transaction transaction; - transaction.request = (struct ofpbuf *) request; + transaction.request = CONST_CAST(struct ofpbuf *, request); transaction.reply = replyp ? ofpbuf_new(1024) : NULL; transactionp = &transaction; diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 02e5aa87..a7d4c734 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -95,7 +95,7 @@ ofpbuf_use_stub(struct ofpbuf *b, void *base, size_t allocated) void ofpbuf_use_const(struct ofpbuf *b, const void *data, size_t size) { - ofpbuf_use__(b, (void *) data, size, OFPBUF_STACK); + ofpbuf_use__(b, CONST_CAST(void *, data), size, OFPBUF_STACK); b->size = size; } @@ -408,7 +408,7 @@ ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n) if (n) { *n = b->size - initial_size; } - return (char *) s; + return CONST_CAST(char *, s); } ofpbuf_put(b, &byte, 1); diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index 3e6f20bb..e357233b 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -884,9 +884,10 @@ ovsdb_datum_default(const struct ovsdb_type *type) d = &default_data[kt][vt]; if (!d->n) { d->n = 1; - d->keys = (union ovsdb_atom *) ovsdb_atom_default(kt); + d->keys = CONST_CAST(union ovsdb_atom *, ovsdb_atom_default(kt)); if (vt != OVSDB_TYPE_VOID) { - d->values = (union ovsdb_atom *) ovsdb_atom_default(vt); + d->values = CONST_CAST(union ovsdb_atom *, + ovsdb_atom_default(vt)); } } return d; diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 3eca2feb..534beb02 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1820,7 +1820,7 @@ ovsdb_idl_txn_write(const struct ovsdb_idl_row *row_, const struct ovsdb_idl_column *column, struct ovsdb_datum *datum) { - struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_; + struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_); const struct ovsdb_idl_table_class *class; size_t column_idx; @@ -1907,7 +1907,7 @@ void ovsdb_idl_txn_verify(const struct ovsdb_idl_row *row_, const struct ovsdb_idl_column *column) { - struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_; + struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_); const struct ovsdb_idl_table_class *class; size_t column_idx; @@ -1946,7 +1946,7 @@ ovsdb_idl_txn_verify(const struct ovsdb_idl_row *row_, void ovsdb_idl_txn_delete(const struct ovsdb_idl_row *row_) { - struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_; + struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_); if (ovsdb_idl_row_is_synthetic(row)) { return; diff --git a/lib/shash.c b/lib/shash.c index 74801763..1cf7d6e1 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 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. @@ -109,7 +109,7 @@ shash_add_nocopy__(struct shash *sh, char *name, const void *data, size_t hash) { struct shash_node *node = xmalloc(sizeof *node); node->name = name; - node->data = (void *) data; + node->data = CONST_CAST(void *, data); hmap_insert(&sh->map, &node->node, hash); return node; } @@ -163,7 +163,7 @@ shash_replace(struct shash *sh, const char *name, const void *data) return NULL; } else { void *old_data = node->data; - node->data = (void *) data; + node->data = CONST_CAST(void *, data); return old_data; } } diff --git a/lib/sset.h b/lib/sset.h index 7f9e1250..f63f4ab9 100644 --- a/lib/sset.h +++ b/lib/sset.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Nicira, Inc. + * Copyright (c) 2011, 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. @@ -18,6 +18,7 @@ #define SSET_H #include "hmap.h" +#include "util.h" #ifdef __cplusplus extern "C" { @@ -82,7 +83,7 @@ bool sset_equals(const struct sset *, const struct sset *); #define SSET_NODE_FROM_HMAP_NODE(HMAP_NODE) \ CONTAINER_OF(HMAP_NODE, struct sset_node, hmap_node) #define SSET_NAME_FROM_HMAP_NODE(HMAP_NODE) \ - ((const char *) (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name)) + (CONST_CAST(const char *, (SSET_NODE_FROM_HMAP_NODE(HMAP_NODE)->name))) #define SSET_NODE_FROM_NAME(NAME) CONTAINER_OF(NAME, struct sset_node, name) #define SSET_FIRST(SSET) SSET_NAME_FROM_HMAP_NODE(hmap_first(&(SSET)->map)) #define SSET_NEXT(SSET, NAME) \ diff --git a/lib/stp.c b/lib/stp.c index ee5c8bcd..3d293b6c 100644 --- a/lib/stp.c +++ b/lib/stp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 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. @@ -151,7 +151,7 @@ stp_next_enabled_port(const struct stp *stp, const struct stp_port *port) { for (; port < &stp->ports[ARRAY_SIZE(stp->ports)]; port++) { if (port->state != STP_DISABLED) { - return (struct stp_port *) port; + return CONST_CAST(struct stp_port *, port); } } return NULL; diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c index f2d5037a..42690e48 100644 --- a/lib/stream-ssl.c +++ b/lib/stream-ssl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 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. @@ -902,7 +902,7 @@ do_ssl_init(void) /* New OpenSSL changed TLSv1_method() to return a "const" pointer, so the * cast is needed to avoid a warning with those newer versions. */ - method = (SSL_METHOD *) TLSv1_method(); + method = CONST_CAST(SSL_METHOD *, TLSv1_method()); if (method == NULL) { VLOG_ERR("TLSv1_method: %s", ERR_error_string(ERR_get_error(), NULL)); return ENOPROTOOPT; diff --git a/lib/util.h b/lib/util.h index 60ec737e..57527fcc 100644 --- a/lib/util.h +++ b/lib/util.h @@ -61,6 +61,16 @@ #define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0) #endif +/* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes + * anything other than an outermost "const" or "volatile" qualifier. + * + * The cast to int is present only to suppress an "expression using sizeof + * bool" warning from "sparse" (see + * http://permalink.gmane.org/gmane.comp.parsers.sparse/2967). */ +#define CONST_CAST(TYPE, POINTER) \ + ((void) sizeof ((int) ((POINTER) == (TYPE) (POINTER))), \ + (TYPE) (POINTER)) + extern const char *program_name; extern const char *subprogram_name; diff --git a/lib/vlog.c b/lib/vlog.c index fc601e8d..683cdfcf 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -762,7 +762,7 @@ void vlog_fatal_valist(const struct vlog_module *module_, const char *message, va_list args) { - struct vlog_module *module = (struct vlog_module *) module_; + struct vlog_module *module = CONST_CAST(struct vlog_module *, module_); /* Don't log this message to the console to avoid redundancy with the * message written by the later ovs_fatal_valist(). */ diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 5ce77c04..d436f779 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -477,7 +477,7 @@ connmgr_free_controller_info(struct shash *info) SHASH_FOR_EACH (node, info) { struct ofproto_controller_info *cinfo = node->data; while (cinfo->pairs.n) { - free((char *) cinfo->pairs.values[--cinfo->pairs.n]); + free(CONST_CAST(char *, cinfo->pairs.values[--cinfo->pairs.n])); } free(cinfo); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index c50353ed..95195a30 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1964,7 +1964,7 @@ bundle_set(struct ofproto *ofproto_, void *aux, break; case PORT_VLAN_TRUNK: - trunks = (unsigned long *) s->trunks; + trunks = CONST_CAST(unsigned long *, s->trunks); break; case PORT_VLAN_NATIVE_UNTAGGED: @@ -1981,7 +1981,7 @@ bundle_set(struct ofproto *ofproto_, void *aux, bitmap_set1(trunks, vlan); bitmap_set0(trunks, 0); } else { - trunks = (unsigned long *) s->trunks; + trunks = CONST_CAST(unsigned long *, s->trunks); } break; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 0f24fd01..cf31a3b2 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -3455,7 +3455,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, fu.hard_timeout = rule->hard_timeout; fu.table_id = rule->table_id; fu.cookie = rule->flow_cookie; - fu.match = (struct cls_rule *) &rule->cr; + fu.match = CONST_CAST(struct cls_rule *, &rule->cr); if (!(flags & NXFMF_ACTIONS)) { fu.ofpacts = NULL; fu.ofpacts_len = 0; diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 6c68e506..1bf10d9b 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -350,8 +350,8 @@ read_map_string_column(const struct ovsdb_row *row, const char *column_name, union ovsdb_atom *atom_key = NULL, *atom_value = NULL; size_t i; - datum = get_datum((struct ovsdb_row *) row, column_name, OVSDB_TYPE_STRING, - OVSDB_TYPE_STRING, UINT_MAX); + datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name, + OVSDB_TYPE_STRING, OVSDB_TYPE_STRING, UINT_MAX); if (!datum) { return NULL; @@ -374,8 +374,8 @@ read_column(const struct ovsdb_row *row, const char *column_name, { const struct ovsdb_datum *datum; - datum = get_datum((struct ovsdb_row *) row, column_name, type, OVSDB_TYPE_VOID, - 1); + datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name, type, + OVSDB_TYPE_VOID, 1); return datum && datum->n ? datum->keys : NULL; } diff --git a/ovsdb/row.c b/ovsdb/row.c index 457869b3..450c3274 100644 --- a/ovsdb/row.c +++ b/ovsdb/row.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 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. @@ -36,7 +36,7 @@ allocate_row(const struct ovsdb_table *table) + sizeof(struct ovsdb_datum) * n_fields + sizeof(struct hmap_node) * n_indexes); struct ovsdb_row *row = xmalloc(row_size); - row->table = (struct ovsdb_table *) table; + row->table = CONST_CAST(struct ovsdb_table *, table); row->txn_row = NULL; list_init(&row->src_refs); list_init(&row->dst_refs); @@ -347,7 +347,7 @@ ovsdb_row_hash_destroy(struct ovsdb_row_hash *rh, bool destroy_rows) HMAP_FOR_EACH_SAFE (node, next, hmap_node, &rh->rows) { hmap_remove(&rh->rows, &node->hmap_node); if (destroy_rows) { - ovsdb_row_destroy((struct ovsdb_row *) node->row); + ovsdb_row_destroy(CONST_CAST(struct ovsdb_row *, node->row)); } free(node); } diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index e785e216..cc890ad8 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. +/* Copyright (c) 2009, 2010, 2011, 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. @@ -439,8 +439,8 @@ static void add_weak_ref(struct ovsdb_txn *txn, const struct ovsdb_row *src_, const struct ovsdb_row *dst_) { - struct ovsdb_row *src = (struct ovsdb_row *) src_; - struct ovsdb_row *dst = (struct ovsdb_row *) dst_; + struct ovsdb_row *src = CONST_CAST(struct ovsdb_row *, src_); + struct ovsdb_row *dst = CONST_CAST(struct ovsdb_row *, dst_); struct ovsdb_weak_ref *weak; if (src == dst) { @@ -864,7 +864,7 @@ ovsdb_txn_row_create(struct ovsdb_txn *txn, struct ovsdb_table *table, const struct ovsdb_row *old_, struct ovsdb_row *new) { const struct ovsdb_row *row = old_ ? old_ : new; - struct ovsdb_row *old = (struct ovsdb_row *) old_; + struct ovsdb_row *old = CONST_CAST(struct ovsdb_row *, old_); size_t n_columns = shash_count(&table->schema->columns); struct ovsdb_txn_table *txn_table; struct ovsdb_txn_row *txn_row; @@ -895,7 +895,7 @@ ovsdb_txn_row_create(struct ovsdb_txn *txn, struct ovsdb_table *table, struct ovsdb_row * ovsdb_txn_row_modify(struct ovsdb_txn *txn, const struct ovsdb_row *ro_row_) { - struct ovsdb_row *ro_row = (struct ovsdb_row *) ro_row_; + struct ovsdb_row *ro_row = CONST_CAST(struct ovsdb_row *, ro_row_); if (ro_row->txn_row) { assert(ro_row == ro_row->txn_row->new); @@ -931,7 +931,7 @@ ovsdb_txn_row_insert(struct ovsdb_txn *txn, struct ovsdb_row *row) void ovsdb_txn_row_delete(struct ovsdb_txn *txn, const struct ovsdb_row *row_) { - struct ovsdb_row *row = (struct ovsdb_row *) row_; + struct ovsdb_row *row = CONST_CAST(struct ovsdb_row *, row_); struct ovsdb_table *table = row->table; struct ovsdb_txn_row *txn_row = row->txn_row; diff --git a/tests/test-stp.c b/tests/test-stp.c index 87c12a0c..0acc7e0d 100644 --- a/tests/test-stp.c +++ b/tests/test-stp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 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. @@ -656,7 +656,7 @@ main(int argc, char *argv[]) for (i = 0; i < tc->n_lans; i++) { struct lan *lan = tc->lans[i]; - free((char *) lan->name); + free(CONST_CAST(char *, lan->name)); free(lan); } for (i = 0; i < tc->n_bridges; i++) { -- 2.30.2