[Openais] [PATCH] fix some lint warnings in objdb.c and totempg.c

angus salkeld angus.salkeld at alliedtelesis.co.nz
Wed Oct 29 16:07:17 PDT 2008


Hi

I ran splint over objdb.c and totempg.c and have here are some minor
lint warning fixes.

Note: I don't need object_iter() & object_iter_reset() but to interface to
it has not been removed from the objdb.h so I assumed the implementation had 
been mistakenly removed.

Regards
Angus

objdb:
	reinstate object_iter() & object_iter_reset()
	extern objdb_iface so it is not declared twice.
	rename the array objdb_iface_ver0 for clarity it is also a type

totempg:
	convert some assert (pointer) to assert (pointer != NULL)
	in totempg_deliver_fn() move the assert above to top most usage of the pointer.
	lint prefers snprintf
---
 exec/Makefile  |    4 +++
 exec/objdb.c   |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 exec/totempg.c |   12 +++++---
 3 files changed, 87 insertions(+), 9 deletions(-)

diff --git a/exec/Makefile b/exec/Makefile
index 307d5ff..b0cdeee 100644
--- a/exec/Makefile
+++ b/exec/Makefile
@@ -137,6 +137,10 @@ liblogsys.so.2.0.0: $(LIBLOGSYS_OBJS)
 
 endif
 
+lint:
+	splint -weak +posixlib +ignoresigns -fcnuse -badflag $(CFLAGS) objdb.c
+	splint -weak +posixlib +ignoresigns -fcnuse -badflag $(CFLAGS) totempg.c
+
 clean:
 	rm -f corosync $(OBJS) *.o *.lcrso libtotem_pg.so* libtotem_pg.a gmon.out 
 	rm -f *.da *.bb *.bbg liblogsys.so* liblogsys.a
diff --git a/exec/objdb.c b/exec/objdb.c
index b0b60bb..c1ad942 100644
--- a/exec/objdb.c
+++ b/exec/objdb.c
@@ -1323,6 +1323,76 @@ error_exit:
 }
 

+static int object_iter_reset(unsigned int parent_object_handle)
+{
+	unsigned int res;
+	struct object_instance *instance;
+
+	objdb_rdlock();
+
+	res = hdb_handle_get (&object_instance_database,
+		parent_object_handle, (void *)&instance);
+	if (res != 0) {
+		goto error_exit;
+	}
+	instance->iter_list = &instance->child_head;
+
+	hdb_handle_put (&object_instance_database, parent_object_handle);
+	objdb_rdunlock();
+	return (0);
+
+error_exit:
+	objdb_rdunlock();
+	return (-1);
+}
+
+static int object_iter(unsigned int parent_object_handle,
+		       void **object_name,
+		       int *name_len,
+		       unsigned int *object_handle)
+{
+	unsigned int res;
+	struct object_instance *instance;
+	struct object_instance *find_instance = NULL;
+	struct list_head *list;
+	unsigned int found = 0;
+
+	objdb_rdlock();
+
+	res = hdb_handle_get (&object_instance_database,
+		parent_object_handle, (void *)&instance);
+	if (res != 0) {
+		goto error_exit;
+	}
+	res = -ENOENT;
+	list = instance->iter_list->next;
+	if (list != &instance->child_head) {
+
+                find_instance = list_entry (list, struct object_instance,
+					    child_list);
+		found = 1;
+	}
+	instance->iter_list = list;
+
+	if (found) {
+		*object_handle = find_instance->object_handle;
+		*object_name = find_instance->object_name;
+		*name_len = find_instance->object_name_len;
+		res = 0;
+	}
+	else {
+		res = -1;
+	}
+	objdb_rdunlock();
+
+	return (res);
+
+error_exit:
+	objdb_rdunlock();
+	return (-1);
+}
+
+
 static int object_parent_get(unsigned int object_handle,
 			     unsigned int *parent_handle)
 {
@@ -1547,7 +1617,9 @@ struct objdb_iface_ver0 objdb_iface = {
 	.object_find_create	= object_find_create,
 	.object_find_next	= object_find_next,
 	.object_find_destroy	= object_find_destroy,
-	.object_key_get		= object_key_get,
+	.object_iter_reset	= object_iter_reset,
+	.object_iter		= object_iter,
+	.object_key_get 	= object_key_get,
 	.object_key_iter_reset	= object_key_iter_reset,
 	.object_key_iter	= object_key_iter,
 	.object_key_iter_from	= object_key_iter_from,
@@ -1563,7 +1635,7 @@ struct objdb_iface_ver0 objdb_iface = {
 	.object_key_decrement   = object_key_decrement,
 };
 
-struct lcr_iface objdb_iface_ver0[1] = {
+struct lcr_iface objdb_iface_array_ver0[1] = {
 	{
 		.name			= "objdb",
 		.version		= 0,
@@ -1579,13 +1651,13 @@ struct lcr_iface objdb_iface_ver0[1] = {
 
 struct lcr_comp objdb_comp_ver0 = {
 	.iface_count			= 1,
-	.ifaces				= objdb_iface_ver0
+	.ifaces				= objdb_iface_array_ver0
 };
 


 __attribute__ ((constructor)) static void objdb_comp_register (void) {
-        lcr_interfaces_set (&objdb_iface_ver0[0], &objdb_iface);
+        lcr_interfaces_set (&objdb_iface_array_ver0[0], &objdb_iface);
 
 	lcr_component_register (&objdb_comp_ver0);
 }
diff --git a/exec/totempg.c b/exec/totempg.c
index 00dfc99..e811126 100644
--- a/exec/totempg.c
+++ b/exec/totempg.c
@@ -266,7 +266,7 @@ static struct assembly *assembly_ref (unsigned int nodeid)
 	/*
 	 * TODO handle memory allocation failure here
 	 */
-	assert (assembly);
+	assert (assembly != NULL);
 	assembly->nodeid = nodeid;
 	list_init (&assembly->list);
 	list_add (&assembly->list, &assembly_list_inuse);
@@ -475,7 +475,7 @@ static void totempg_deliver_fn (
 	int start;
 
 	assembly = assembly_ref (nodeid);
-	assert (assembly);
+	assert (assembly != NULL);
 
 	/*
 	 * Assemble the header into one block of data and
@@ -489,6 +489,7 @@ static void totempg_deliver_fn (
 		char *data;
 		int datasize;
 
+		assert(iovec != NULL);
 		mcast = (struct totempg_mcast *)iovec[0].iov_base;
 		if (endian_conversion_required) {
 			mcast->msg_count = swab16 (mcast->msg_count);
@@ -497,9 +498,10 @@ static void totempg_deliver_fn (
 		msg_count = mcast->msg_count;
 		datasize = sizeof (struct totempg_mcast) +
 			msg_count * sizeof (unsigned short);
-		
+
+		assert (datasize < FRAME_SIZE_MAX);
+
 		memcpy (header, iovec[0].iov_base, datasize);
-		assert(iovec);
 		data = iovec[0].iov_base;
 
 		msg_lens = (unsigned short *) (header + sizeof (struct totempg_mcast));
@@ -1236,7 +1238,7 @@ char *totempg_ifaces_print (unsigned int nodeid)
 	}
 
 	for (i = 0; i < iface_count; i++) {
-		sprintf (one_iface, "r(%d) ip(%s) ",
+		snprintf (one_iface, 64, "r(%d) ip(%s) ",
 			i, totemip_print (&interfaces[i]));
 		strcat (iface_string, one_iface);
 	}
-- 
1.5.6



More information about the Openais mailing list