Here's an incremental
---
lib/netdev.c | 9 ++++-----
lib/smap.c | 27 ++++++++++++++-------------
lib/smap.h | 11 ++++++-----
utilities/ovs-dpctl.c | 4 ++--
4 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/lib/netdev.c b/lib/netdev.c
index 1c3a01d..1b76785 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1067,9 +1067,8 @@ netdev_get_n_queues(const struct netdev *netdev,
* A '*typep' of "" indicates that QoS is currently disabled on 'netdev'.
*
* The caller must initialize 'details' as an empty smap (e.g. with
- * smap_init()) before calling this function. The caller must free 'details',
- * including 'data' members, when it is no longer needed (e.g. with
- * smap_destroy()).
+ * smap_init()) before calling this function. The caller must free 'details'
+ * when it is no longer needed (e.g. with smap_destroy()).
*
* The caller must not modify or free '*typep'.
*
@@ -1149,8 +1148,8 @@ netdev_set_qos(struct netdev *netdev,
* vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
*
* The caller must initialize 'details' (e.g. with smap_init()) before calling
- * this function. The caller must free 'details', including 'data' members,
- * when it is no longer needed (e.g. with smap_destroy()). */
+ * this function. The caller must free 'details' when it is no longer needed
+ * (e.g. with smap_destroy()). */
int
netdev_get_queue(const struct netdev *netdev,
unsigned int queue_id, struct smap *details)
diff --git a/lib/smap.c b/lib/smap.c
index 64de4a3..642804e 100644
--- a/lib/smap.c
+++ b/lib/smap.c
@@ -21,8 +21,8 @@
static struct smap_node *smap_add__(struct smap *, char *, void *,
size_t hash);
-static struct smap_node * smap_find__(const struct smap *, const char *key,
- size_t key_len, size_t hash);
+static struct smap_node *smap_find__(const struct smap *, const char *key,
+ size_t key_len, size_t hash);
static int compare_nodes_by_key(const void *, const void *);
/* Public Functions. */
@@ -47,8 +47,9 @@ smap_destroy(struct smap *smap)
struct smap_node *
smap_add(struct smap *smap, const char *key, const char *value)
{
- return smap_add__(smap, xstrdup(key), xstrdup(value),
- hash_bytes(key, strlen(key), 0));
+ size_t key_len = strlen(key);
+ return smap_add__(smap, xmemdup0(key, key_len), xstrdup(value),
+ hash_bytes(key, key_len, 0));
}
/* Attempts to add 'key' to 'smap' associated with 'value'. If 'key' already
@@ -70,6 +71,7 @@ smap_add_once(struct smap *smap, const char *key, const char
*value)
void
smap_add_format(struct smap *smap, const char *key, const char *format, ...)
{
+ size_t key_len;
va_list args;
char *value;
@@ -77,7 +79,9 @@ smap_add_format(struct smap *smap, const char *key, const
char *format, ...)
value = xvasprintf(format, args);
va_end(args);
- smap_add__(smap, xstrdup(key), value, hash_bytes(key, strlen(key), 0));
+ key_len = strlen(key);
+ smap_add__(smap, xmemdup0(key, key_len), value,
+ hash_bytes(key, key_len, 0));
}
/* Searches for 'key' in 'smap'. If it does not already exists, adds it.
@@ -85,7 +89,7 @@ smap_add_format(struct smap *smap, const char *key, const
char *format, ...)
void
smap_replace(struct smap *smap, const char *key, const char *value)
{
- int key_len = strlen(key);
+ size_t key_len = strlen(key);
size_t hash = hash_bytes(key, key_len, 0);
struct smap_node *node;
@@ -95,7 +99,7 @@ smap_replace(struct smap *smap, const char *key, const char
*value)
free(node->value);
node->value = xstrdup(value);
} else {
- smap_add__(smap, xstrdup(key), xstrdup(value), hash);
+ smap_add__(smap, xmemdup0(key, key_len), xstrdup(value), hash);
}
}
@@ -127,10 +131,7 @@ smap_clear(struct smap *smap)
struct smap_node *node, *next;
SMAP_FOR_EACH_SAFE (node, next, smap) {
- hmap_remove(&smap->map, &node->node);
- free(node->key);
- free(node->value);
- free(node);
+ smap_remove_node(smap, node);
}
}
@@ -146,7 +147,7 @@ smap_get(const struct smap *smap, const char *key)
struct smap_node *
smap_get_node(const struct smap *smap, const char *key)
{
- int key_len = strlen(key);
+ size_t key_len = strlen(key);
return smap_find__(smap, key, key_len, hash_bytes(key, key_len, 0));
}
@@ -163,7 +164,7 @@ smap_get_bool(const struct smap *smap, const char *key,
bool def)
}
if (def) {
- return !strcasecmp("false", value);
+ return strcasecmp("false", value) != 0;
} else {
return !strcasecmp("true", value);
}
diff --git a/lib/smap.h b/lib/smap.h
index cabdcc0..77a4c7a 100644
--- a/lib/smap.h
+++ b/lib/smap.h
@@ -17,16 +17,17 @@
#include "hmap.h"
+/* A map from strings to string. */
+struct smap {
+ struct hmap map; /* Contains "struct smap_node"s. */
+};
+
struct smap_node {
- struct hmap_node node;
+ struct hmap_node node; /* In struct smap's 'map' hmap. */
char *key;
char *value;
};
-struct smap {
- struct hmap map;
-};
-
#define SMAP_INITIALIZER(SMAP) { HMAP_INITIALIZER(&(SMAP)->map) }
#define SMAP_FOR_EACH(SMAP_NODE, SMAP) \
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index 1bb2951..950e8f4 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -512,8 +512,8 @@ show_dpif(struct dpif *dpif)
nodes = smap_sort(&config);
for (i = 0; i < smap_count(&config); i++) {
const struct smap_node *node = nodes[i];
- printf("%c %s=%s", i ? ',' : ':',
- node->key, (char *) node->value);
+ printf("%c %s=%s", i ? ',' : ':', node->key,
+ node->value);
}
free(nodes);
} else {
--
1.7.10.2
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev