From e893e6de59d72aefa5590dc1b33e233a6b80d9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Wed, 20 Dec 2017 22:07:24 +0100 Subject: [PATCH] warnings cleanup: Wsign-compare: hdb: uint32_t <-> int32_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When at it, also document that qb_hdb_handle_get_always is an alias to qb_hdb_handle_get. Signed-off-by: Jan Pokorný --- include/qb/qbhdb.h | 1 + lib/hdb.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/qb/qbhdb.h b/include/qb/qbhdb.h index 25fc9a4..87b2292 100644 --- a/include/qb/qbhdb.h +++ b/include/qb/qbhdb.h @@ -123,6 +123,7 @@ int32_t qb_hdb_handle_get(struct qb_hdb *hdb, qb_handle_t handle_in, * @param hdb the database instance * @param instance (out) pointer to the desired object. * @return (0 == ok, -errno failure) + * @note This is currently an alias to @ref qb_hdb_handle_get. */ int32_t qb_hdb_handle_get_always(struct qb_hdb *hdb, qb_handle_t handle_in, void **instance); diff --git a/lib/hdb.c b/lib/hdb.c index 1135b8c..2aafdca 100644 --- a/lib/hdb.c +++ b/lib/hdb.c @@ -80,7 +80,7 @@ qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size, } if (found == QB_FALSE) { - res = qb_array_grow(hdb->handles, handle_count + 1); + res = qb_array_grow(hdb->handles, handle_count + 1U); if (res != 0) { return res; } @@ -89,6 +89,8 @@ qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size, if (res != 0) { return res; } + /* NB: qb_array_grow above guarantees that handle_count + will not overflow INT32_MAX */ qb_atomic_int_inc((int32_t *)&hdb->handle_count); } @@ -127,7 +129,7 @@ int32_t qb_hdb_handle_get(struct qb_hdb * hdb, qb_handle_t handle_in, void **instance) { int32_t check = handle_in >> 32; - uint32_t handle = handle_in & UINT32_MAX; + int32_t handle = handle_in & UINT32_MAX; struct qb_hdb_handle *entry; int32_t handle_count; @@ -165,7 +167,7 @@ int32_t qb_hdb_handle_put(struct qb_hdb * hdb, qb_handle_t handle_in) { int32_t check = handle_in >> 32; - uint32_t handle = handle_in & UINT32_MAX; + int32_t handle = handle_in & UINT32_MAX; struct qb_hdb_handle *entry; int32_t handle_count; @@ -195,7 +197,7 @@ int32_t qb_hdb_handle_destroy(struct qb_hdb * hdb, qb_handle_t handle_in) { int32_t check = handle_in >> 32; - uint32_t handle = handle_in & UINT32_MAX; + int32_t handle = handle_in & UINT32_MAX; int32_t res; struct qb_hdb_handle *entry; int32_t handle_count; @@ -221,7 +223,7 @@ int32_t qb_hdb_handle_refcount_get(struct qb_hdb * hdb, qb_handle_t handle_in) { int32_t check = handle_in >> 32; - uint32_t handle = handle_in & UINT32_MAX; + int32_t handle = handle_in & UINT32_MAX; struct qb_hdb_handle *entry; int32_t handle_count; int32_t refcount = 0; @@ -255,7 +257,7 @@ qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance, qb_handle_t * handle) int32_t res = -1; uint64_t checker; struct qb_hdb_handle *entry; - int32_t handle_count; + uint32_t handle_count; handle_count = qb_atomic_int_get(&hdb->handle_count); while (hdb->iterator < handle_count) {