#985479 hdbm.c: add a comment to show more information about a pointer type mismatch

Package:
src:nn
Source:
nn
Submitter:
Bjarni Ingi Gislason
Date:
2021-03-19 02:03:04 UTC
Severity:
normal
Tags:
#985479#5
Date:
2021-03-19 01:59:32 UTC
From:
To:
Dear Maintainer,

hdbm.c:147:48: warning: pointer type mismatch in conditional expression
  147 |     tbl->ht_hash = (hashfunc == NULL ? hdbmdef : hashfunc);
      |                                                ^
  and a more informative warning with a test code:

hdbm.c:149:18: warning: assignment to 'unsigned int (*)(struct hdbmdatum)' from incompatible pointer type 'unsigned int (*)(void)' [-Wincompatible-pointer-types]
  149 |     tbl->ht_hash = hashfunc;
      |                  ^

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
 hdbm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hdbm.c b/hdbm.c
index b5bbf22..54910cd 100644
--- a/hdbm.c
+++ b/hdbm.c
@@ -144,6 +144,18 @@ hdbmcreate(register unsigned size, unsigned (*hashfunc) (void))
     tbl = &aap->ht;
     tbl->ht_size = (size == 0 ? 1 : size);	/* size of 0 is nonsense */
     tbl->ht_magic = HASHMAG;
+/* Next line produces a warning:
+ *
+hdbm.c:147:48: warning: pointer type mismatch in conditional expression
+  147 |     tbl->ht_hash = (hashfunc == NULL ? hdbmdef : hashfunc);
+      |                                                ^
+ *
+ * and with more information from a test code:
+ *
+hdbm.c:149:18: warning: assignment to 'unsigned int (*)(struct hdbmdatum)' from incompatible pointer type 'unsigned int (*)(void)' [-Wincompatible-pointer-types]
+  149 |     tbl->ht_hash = hashfunc;
+      |                  ^
+ */
     tbl->ht_hash = (hashfunc == NULL ? hdbmdef : hashfunc);
     tbl->ht_addr = hepp = aap->hepa;
     while (size-- > 0)