> Proposed changes are in attachment. These changes passed CI: 
> https://github.com/maiddaisuki/mingw-w64/actions/runs/27751004928.

I noticed that I missed a stupid off-by-one error when calculating buffer size:

> +    /**
> +     * Estimate maximum buffer size assuming that each wide character 
> converts
> +     * to at least 1 byte and at most `MB_LEN_MAX` bytes.
> +     */
> +    int message_length = wcsnlen (_Message, BUFSIZ) * MB_LEN_MAX;
> +    int file_length = wcsnlen (_File, FILENAME_MAX) * MB_LEN_MAX;
> +
> +    message_length = __min (message_length, BUFSIZ);
> +    file_length = __min (file_length, FILENAME_MAX);

It would be more appropriate to have:

```
  int message_length = (wcsnlen (_Message, BUFSIZ) * MB_LEN_MAX) + 1;
  int file_length = (wcsnlen (_File, FILENAME_MAX) * MB_LEN_MAX) + 1;
```

To ensure that we allocate at least one byte in case if any argument is an 
empty string; otherwise, `_alloca` will allocate zero bytes on stack which 
later will be dereferenced by `_assert`.

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to