On Thu, 20 Mar 2025, Pali Rohár wrote:
They are natively available since msvcr80.dll, they are not available in
msvcrt.dll. Provide compatibility emulation into all import libraries where
they are not available.
Adjust check for _aligned_msize() which is also available since
msvcr80.dll.
---
mingw-w64-crt/Makefile.am | 6 ++++++
mingw-w64-crt/misc/_aligned_offset_recalloc.c | 16 ++++++++++++++++
mingw-w64-crt/misc/_aligned_recalloc.c | 16 ++++++++++++++++
mingw-w64-crt/misc/_recalloc.c | 16 ++++++++++++++++
mingw-w64-headers/crt/crtdbg.h | 2 +-
mingw-w64-headers/crt/malloc.h | 2 +-
mingw-w64-headers/crt/stdlib.h | 2 +-
7 files changed, 57 insertions(+), 3 deletions(-)
create mode 100644 mingw-w64-crt/misc/_aligned_offset_recalloc.c
create mode 100644 mingw-w64-crt/misc/_aligned_recalloc.c
create mode 100644 mingw-w64-crt/misc/_recalloc.c
diff --git a/mingw-w64-crt/misc/_recalloc.c b/mingw-w64-crt/misc/_recalloc.c
new file mode 100644
index 000000000000..5eaecccf1306
--- /dev/null
+++ b/mingw-w64-crt/misc/_recalloc.c
@@ -0,0 +1,16 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <malloc.h>
+
+void * __cdecl _recalloc(void *memory, size_t count, size_t size)
+{
+ size_t total_size;
+ if (__builtin_mul_overflow(count, size, &total_size))
+ return NULL;
+ return realloc(memory, total_size);
+}
This doesn't seem right; isn't _recalloc supposed to zero-initialize the
newly allocated memory - which standard realloc() doesn't do? (The same
goes for all the other functions in this patch as well.)
I guess it should be possible to implement this properly using _msize()?
// Martin
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public