Starting from this warning (1 of 4 identical):

    confdb.c:559: warning: passing argument 4 of 'api->object_find_create'
      from incompatible pointer type
    confdb.c:559: note: expected 'hdb_handle_t *' but argument is of type
      'mar_uint64_t *'

Here's the offending code in services/confdb.c:

static void message_handler_req_lib_confdb_object_iter (void *conn,
                                                        const void *message)
{
        const struct req_lib_confdb_object_iter *req_lib_confdb_object_iter
          = message;
        struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
        size_t object_name_len;
        int ret = CS_OK;

        if (!req_lib_confdb_object_iter->find_handle) {
                
api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
                                        NULL, 0,
=== line 559 ===============>           
&res_lib_confdb_object_iter.find_handle);
        }

As the warning says, &...find_handle member has type mar_uint64_t *,
but the function expects hdb_handle_t*.  The latter is defined like this:

    typedef unsigned long long hdb_handle_t

Wondering if the warning was legit,
I had to first find a place where that 4th argument is used.
It looks like there's one in objdb.c:

static int object_find_create (
        hdb_handle_t object_handle,
        const void *object_name,
        size_t object_len,
        hdb_handle_t *object_find_handle)
{
        unsigned int res;
        struct object_instance *object_instance;
        struct object_find_instance *object_find_instance;

        objdb_rdlock();
        res = hdb_handle_get (&object_instance_database,
                object_handle, (void *)&object_instance);
        if (res != 0) {
                goto error_exit;
        }

        res = hdb_handle_create (&object_find_instance_database,
                sizeof (struct object_find_instance), object_find_handle);
        if (res != 0) {
                goto error_put;
        }
        res = hdb_handle_get (&object_find_instance_database,
=== deref =>    *object_find_handle, (void *)&object_find_instance);
        if (res != 0) {

And it is dereferenced.
That means for the complained-about line to be valid,
the dereferenced types must have the same size and lay-out.
They do, so we're ok.

Now that we know it's ok to suppress the warning,
the trick is to do it in a not-to-risky way.
The risky way would be to use a (void*) or (hdb_handle_t*) cast,
but that would make it so any later change of that type would not
propagate past the cast, and the compiler would not be able to help.

I wrote this patch:

>From 2ff13de80526c47e0fce8f80103db7994408d9a3 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Mon, 20 Apr 2009 16:17:05 +0200
Subject: [PATCH] services/confdb.c: avoid four warnings

* services/confdb.c (m2h): New function.
(message_handler_req_lib_confdb_object_iter): Use m2h rather than a cast.
(message_handler_req_lib_confdb_object_find): Likewise.
---
 services/confdb.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/services/confdb.c b/services/confdb.c
index dcce7d2..a3a60b5 100644
--- a/services/confdb.c
+++ b/services/confdb.c
@@ -54,6 +54,15 @@

 LOGSYS_DECLARE_SUBSYS ("CONFDB");

+static hdb_handle_t *
+m2h (mar_uint64_t *m)
+{
+       /* FIXME enable the following when/if we use gnulib:
+          (it's a compile-time assertion; i.e., zero run-time cost)
+          verify (sizeof (*m) == sizeof (hdb_handle_t)); */
+       return (void *) m;
+}
+
 static struct corosync_api_v1 *api;

 static int confdb_exec_init_fn (
@@ -556,13 +565,13 @@ static void message_handler_req_lib_confdb_object_iter 
(void *conn,
        if (!req_lib_confdb_object_iter->find_handle) {
                
api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
                                        NULL, 0,
-                                       
&res_lib_confdb_object_iter.find_handle);
+                                       
m2h(&res_lib_confdb_object_iter.find_handle));
        }
        else
                res_lib_confdb_object_iter.find_handle = 
req_lib_confdb_object_iter->find_handle;

        if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
-                                 &res_lib_confdb_object_iter.object_handle)) {
+                                 
m2h(&res_lib_confdb_object_iter.object_handle))) {
                ret = CS_ERR_ACCESS;
                
api->object_find_destroy(res_lib_confdb_object_iter.find_handle);
        }
@@ -592,13 +601,13 @@ static void message_handler_req_lib_confdb_object_find 
(void *conn,
                
api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
                                        
req_lib_confdb_object_find->object_name.value,
                                        
req_lib_confdb_object_find->object_name.length,
-                                       
&res_lib_confdb_object_find.find_handle);
+                                       
m2h(&res_lib_confdb_object_find.find_handle));
        }
        else
                res_lib_confdb_object_find.find_handle = 
req_lib_confdb_object_find->find_handle;

        if (api->object_find_next(res_lib_confdb_object_find.find_handle,
-                                 &res_lib_confdb_object_find.object_handle)) {
+                                 
m2h(&res_lib_confdb_object_find.object_handle))) {
                ret = CS_ERR_ACCESS;
                
api->object_find_destroy(res_lib_confdb_object_find.find_handle);
        }
--
1.6.3.rc0.230.g3edd6
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to