git » nmdb » commit 33377d0

Fail if we try to operate with the db if we haven't added any servers yet.

author Alberto Bertogli
2007-06-01 15:52:51 UTC
committer Alberto Bertogli
2007-06-01 15:52:51 UTC
parent ed2d3b2fbfc1bbd31be1b7e401edb6c3c35488bd

Fail if we try to operate with the db if we haven't added any servers yet.

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

libnmdb/libnmdb.c +9 -0

diff --git a/libnmdb/libnmdb.c b/libnmdb/libnmdb.c
index c9450b3..e000d46 100644
--- a/libnmdb/libnmdb.c
+++ b/libnmdb/libnmdb.c
@@ -296,6 +296,9 @@ static int tcp_srv_send(struct nmdb_srv *srv,
 static int srv_send(struct nmdb_srv *srv,
 		const unsigned char *buf, size_t bsize)
 {
+	if (srv == NULL)
+		return 0;
+
 	if (srv->type == TIPC_CONN)
 		return tipc_srv_send(srv, buf, bsize);
 	else if (srv->type == TCP_CONN)
@@ -375,6 +378,9 @@ static uint32_t get_rep(struct nmdb_srv *srv,
 		unsigned char *buf, size_t bsize,
 		unsigned char **payload, size_t *psize)
 {
+	if (srv == NULL)
+		return -1;
+
 	if (srv->type == TIPC_CONN)
 		return tipc_get_rep(srv, buf, bsize, payload, psize);
 	else if (srv->type == TCP_CONN)
@@ -409,6 +415,9 @@ static struct nmdb_srv *select_srv(nmdb_t *db,
 {
 	uint32_t n;
 
+	if (db->nservers == 0)
+		return NULL;
+
 	n = checksum(key, ksize) % db->nservers;
 	return &(db->servers[n]);
 }