git » nmdb » commit ba6c629

nmdb: Cast to avoid known const violation warnings in tdb and bdb backends

author Alberto Bertogli
2010-04-25 06:43:13 UTC
committer Alberto Bertogli
2010-04-25 06:43:13 UTC
parent fe6f45bb8e5916df6787a99d58d797c74d42fb08

nmdb: Cast to avoid known const violation warnings in tdb and bdb backends

tdb and bdb APIs make it difficult to maintain const warranties, although
they do not modify the buffers.

This causes the compiler to emit a warning, which is distracting since it
is a known but harmless issue.

This patch adds casts to avoid the warnings. It was tested with gcc 4.4.3
and clang 1.1 (svn rev 98154).

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

nmdb/be-bdb.c +5 -5
nmdb/be-tdb.c +5 -6

diff --git a/nmdb/be-bdb.c b/nmdb/be-bdb.c
index 33a3f0f..edfd0d1 100644
--- a/nmdb/be-bdb.c
+++ b/nmdb/be-bdb.c
@@ -78,10 +78,10 @@ int bdb_set(struct db_conn *db, const unsigned char *key, size_t ksize,
 	memset(&v, 0, sizeof(DBT));
 
 	/* we can't maintain "const"ness here because bdb's prototypes; the
-	 * same applies to get and del */
-	k.data = key;
+	 * same applies to get and del, so we just cast */
+	k.data = (unsigned char *) key;
 	k.size = ksize;
-	v.data = val;
+	v.data = (unsigned char *) val;
 	v.size = vsize;
 
 	rv = bdb_db->put(bdb_db, NULL, &k, &v, 0);
@@ -101,7 +101,7 @@ int bdb_get(struct db_conn *db, const unsigned char *key, size_t ksize,
 	memset(&k, 0, sizeof(DBT));
 	memset(&v, 0, sizeof(DBT));
 
-	k.data = key;
+	k.data = (unsigned char *) key;
 	k.size = ksize;
 	v.data = val;
 	v.ulen = *vsize;
@@ -125,7 +125,7 @@ int bdb_del(struct db_conn *db, const unsigned char *key, size_t ksize)
 	memset(&k, 0, sizeof(DBT));
 	memset(&v, 0, sizeof(DBT));
 
-	k.data = key;
+	k.data = (unsigned char *) key;
 	k.size = ksize;
 
 	rv = bdb_db->del(bdb_db, NULL, &k, 0);
diff --git a/nmdb/be-tdb.c b/nmdb/be-tdb.c
index 9a578bb..bd81789 100644
--- a/nmdb/be-tdb.c
+++ b/nmdb/be-tdb.c
@@ -63,22 +63,21 @@ int xtdb_set(struct db_conn *db, const unsigned char *key, size_t ksize,
 	TDB_DATA k, v;
 
 	/* we can't maintain "const"ness here because tdb's prototypes; the
-	 * same applies to get and del */
-	k.dptr = key;
+	 * same applies to get and del, so we just cast */
+	k.dptr = (unsigned char *) key;
 	k.dsize = ksize;
-	v.dptr = val;
+	v.dptr = (unsigned char *) val;
 	v.dsize = vsize;
 
 	return tdb_store(db->conn, k, v, TDB_REPLACE) == 0;
 }
 
-
 int xtdb_get(struct db_conn *db, const unsigned char *key, size_t ksize,
 		unsigned char *val, size_t *vsize)
 {
 	TDB_DATA k, v;
 
-	k.dptr = key;
+	k.dptr = (unsigned char *) key;
 	k.dsize = ksize;
 
 	v = tdb_fetch(db->conn, k);
@@ -98,7 +97,7 @@ int xtdb_del(struct db_conn *db, const unsigned char *key, size_t ksize)
 {
 	TDB_DATA k;
 
-	k.dptr = key;
+	k.dptr = (unsigned char *) key;
 	k.dsize = ksize;
 
 	return tdb_delete(db->conn, k) == 0;