summaryrefslogtreecommitdiff
path: root/src/udev/udevadm-hwdb.c
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2012-10-25 21:39:01 +0200
committerKay Sievers <kay@vrfy.org>2012-10-25 21:44:33 +0200
commitc225f2ffc8a44d9796723aa97bbdfcf331a836c5 (patch)
treebce6bf10440697227d19400ebfa566d8235e88b9 /src/udev/udevadm-hwdb.c
parentf3b9526171eceb885c8365c46e11aa27e8cdad13 (diff)
udev: hwdb - properly initialize search structure
Diffstat (limited to 'src/udev/udevadm-hwdb.c')
-rw-r--r--src/udev/udevadm-hwdb.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index 52fe1d4ebc..ce8eff4811 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -135,19 +135,28 @@ static int trie_values_cmp(const void *v1, const void *v2, void *arg) {
static int trie_node_add_value(struct trie *trie, struct trie_node *node,
const char *key, const char *value) {
- size_t k, v;
+ ssize_t k, v;
struct trie_value_entry *val;
- struct trie_value_entry search;
k = strbuf_add_string(trie->strings, key, strlen(key));
+ if (k < 0)
+ return k;
v = strbuf_add_string(trie->strings, value, strlen(value));
+ if (v < 0)
+ return v;
- /* replace existing earlier key with new value */
- search.value_off = k;
- val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
- if (val) {
- val->value_off = v;
- return 0;
+ if (node->values_count) {
+ struct trie_value_entry search = {
+ .key_off = k,
+ .value_off = v,
+ };
+
+ val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
+ if (val) {
+ /* replace existing earlier key with new value */
+ val->value_off = v;
+ return 0;
+ }
}
/* extend array, add new entry, sort for bisection */