Hello,

We’ve seen a compiler warning in the vasnprintf module (as copied into
GLib) when building with GCC 14 (on msys2, although I don’t think
that’s relevant).

```
../glib/gnulib/vasnprintf.c: In function 'multiply':
../glib/gnulib/vasnprintf.c:382:21: error: allocation of insufficient
size '1' for type 'mp_limb_t' {aka 'unsigned int'} with size '4' [-
Werror=alloc-size]
  382 |       dest->limbs = (mp_limb_t *) malloc (1);
      |                     ^
cc1.exe: all warnings being treated as errors
```

This is for the following code in vasnprintf.c:
```
if (len1 == 0)
  {
    /* src1 or src2 is zero.  */
    dest->nlimbs = 0;
    dest->limbs = (mp_limb_t *) malloc (1);
  }
```

Given that it’s setting `nlimbs = 0`, I suspect that the allocation is
a dummy and doesn’t actually need to contain a full `mp_limb_t`. The
compiler can’t know that though.

The fix we’ve put together for GLib is here, and makes the obvious
switch from allocating one byte to allocating `sizeof (mp_limb_t)`:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4066/diffs?commit_id=cbc58085455b699e9ccd73f30eed72510ead5813

I don’t know if you want to incorporate that fix, or to go with an
alternative like using a pragma to ignore the -Walloc-size warning
around that area of code.

(Please keep me in CC as I am not subscribed to this list.)

Thanks,
Philip

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to