[Bug 279054] Compile failure when #include <netlink/netlink_snl.h> in C++ code

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 17 May 2024 10:59:00 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279054

            Bug ID: 279054
           Summary: Compile failure when #include <netlink/netlink_snl.h>
                    in C++ code
           Product: Base System
           Version: 14.0-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: misc
          Assignee: bugs@FreeBSD.org
          Reporter: cnbatch@gmail.com

Both FreeBSD 14 and 15 generated the same errors. 

C++ Codes:

```
#include <netlink/netlink_snl.h>

int main()
{
    snl_state st{};
    return 0;
}
```


Errors:


In file included from main.cpp:1:
/usr/include/netlink/netlink_snl.h:83:24: error: cannot initialize a variable
of type 'struct linear_buffer *' with an rvalue of type 'void *'
   83 |         struct linear_buffer *lb = calloc(1, size);
      |                               ^    ~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:107:9: error: cannot initialize return
object of type 'char *' with an lvalue of type 'void *'
  107 |         return (data);
      |                ^~~~~~
/usr/include/netlink/netlink_snl.h:278:12: error: assigning to 'char *' from
incompatible type 'void *'
  278 |         ss->buf = malloc(ss->bufsize);
      |                   ^~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:498:2: error: no matching function for call
to 'snl_parse_fields'
  498 |         snl_parse_fields(ss, hdr, parser->in_hdr_size, parser->fp,
parser->fp_size, target);
      |         ^~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:479:1: note: candidate function not viable:
cannot convert argument of incomplete type 'void *' to 'struct nlmsghdr *' for
2nd argument
  479 | snl_parse_fields(struct snl_state *ss, struct nlmsghdr *hdr, int hdrlen
__unused,
      | ^                                      ~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:619:8: error: cannot initialize a variable
of type 'char *' with an rvalue of type 'void *'
  619 |         char *buf = snl_allocz(ss, maxlen + 1);
      |               ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:636:3: error: no matching function for call
to 'strlcpy'
  636 |                 strlcpy(target, tmp, (size_t)arg);
      |                 ^~~~~~~
/usr/include/string.h:98:9: note: candidate function not viable: cannot convert
argument of incomplete type 'void *' to 'char *__restrict' for 1st argument
   98 | size_t   strlcpy(char * __restrict, const char * __restrict, size_t);
      |          ^       ~~~~~~
In file included from main.cpp:1:
/usr/include/netlink/netlink_snl.h:649:9: error: cannot initialize a variable
of type 'char *' with an rvalue of type 'void *'
  649 |                 char *buf = snl_allocz(ss, maxlen);
      |                       ^     ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:678:21: error: cannot initialize a variable
of type 'struct snl_parray *' with an lvalue of type 'void *'
  678 |         struct snl_parray *array = target;
      |                            ^       ~~~~~~
/usr/include/netlink/netlink_snl.h:685:17: error: assigning to 'void **' from
incompatible type 'void *'
  685 |         array->items = snl_allocz(ss, size * sizeof(void *));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:701:2: error: assigning to 'struct nlattr *'
from incompatible type 'void *'
  701 |         NLA_FOREACH(nla, NLA_DATA(container_nla),
NLA_DATA_LEN(container_nla)) {
      |        
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:66:22: note: expanded from macro
'NLA_FOREACH'
   66 |         for (_attr = (_start);          \
      |                      ^~~~~~~~
/usr/include/netlink/netlink_snl.h:715:11: error: cannot initialize a variable
of type 'void **' with an rvalue of type 'void *'
  715 |                         void **new_array = snl_allocz(ss, new_size
*sizeof(void *));
      |                                ^          
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:828:26: error: cannot initialize a variable
of type 'struct snl_attr_bitset *' with an lvalue of type 'void *'
  828 |         struct snl_attr_bitset *target = _target;
      |                                 ^        ~~~~~~~
/usr/include/netlink/netlink_snl.h:864:26: error: cannot initialize a variable
of type 'struct snl_attr_bitset *' with an lvalue of type 'void *'
  864 |         struct snl_attr_bitset *target = _target;
      |                                 ^        ~~~~~~~
/usr/include/netlink/netlink_snl.h:984:11: error: no matching function for call
to 'snl_parse_attrs_raw'
  984 |                 return (snl_parse_attrs_raw(ss, data, len, ps->np,
ps->np_size, attrs));
      |                         ^~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:448:1: note: candidate function not viable:
cannot convert argument of incomplete type 'void *' to 'struct nlattr *' for
2nd argument
  448 | snl_parse_attrs_raw(struct snl_state *ss, struct nlattr *nla_head, int
len,
      | ^                                         ~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:1026:13: error: assigning to 'char *' from
incompatible type 'void *'
 1026 |         nw->base = snl_allocz(ss, nw->size);
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/netlink/netlink_snl.h:1064:14: error: assigning to 'char *' from
incompatible type 'void *'
 1064 |                 nw->base = new_base;
      |                            ^~~~~~~~
16 errors generated.

-- 
You are receiving this mail because:
You are the assignee for the bug.