https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=289835

            Bug ID: 289835
           Summary: Build failure with Clang/LLVM 22 due to alloc-size
                    diagnostic
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: [email protected]
          Reporter: [email protected]

This report is to register in Bugzilla the content I posted on the mailing
list:
https://lists.freebsd.org/archives/freebsd-hackers/2025-September/005103.html

The following is a repost.
---
There is a new diagnostic, alloc-size, in clang of LLVM22 that warns if the
size given to a malloc is smaller than the size of the struct pointed to by
its destination - https://github.com/llvm/llvm-project/pull/150028
When we enable this option, in_mcast.c triggers this diagnostic, causing
the build to fail.

```
freebsd/sys/netinet/in_mcast.c:749:10: error: allocation of insufficient
size '40' for type 'struct ip_msource' with size '48' [-Werror,-Walloc-size]
  749 |                 nims = malloc(sizeof(struct in_msource),
M_INMFILTER,
      |                        ^
```

https://github.com/freebsd/freebsd-src/blob/stable/15/sys/netinet/in_mcast.c#L749
```
static int
imf_get_source(struct in_mfilter *imf, const struct sockaddr_in *psin,
    struct in_msource **plims)
{
          ...
struct ip_msource *ims, *nims;
  ...
nims = malloc(sizeof(struct in_msource), M_INMFILTER,
   M_NOWAIT | M_ZERO);
```

As the error message explained, the mismatch between struct ip_msource *
and malloc(sizeof(struct in_msource)) triggers the error.

However, when reading the source code carefully, it seems that *nims is
intentionally of type ip_msource instead of in_msource.
---

Some people might say that this is a false positive in LLVM diagnostic. But
Zhenlei's suggestion
https://lists.freebsd.org/archives/freebsd-hackers/2025-September/005106.html
could avoid the error although ideally it might be better to use a union{} for
this data as Paul mentioned in the following thread.
Additionally, the only code that actually triggers the alloc-size diagnostic is
this in_mcast and in6_mcast code. So, it would be great if the code is changed.

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

Reply via email to