rv_alloc(struct _reent *ptr, int i)
#endif
{
- int j, k, *r;
+ int j;
+ char *r;
+ /* Allocate buffer in a compatible way with legacy _ldtoa_r(). */
j = sizeof(ULong);
- for(k = 0;
- sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
- j <<= 1)
- k++;
- r = (int*)Balloc(ptr, k);
+ for (_REENT_MP_RESULT_K (ptr) = 0;
+ sizeof (Bigint) - sizeof (ULong) + j <= i; j <<= 1)
+ _REENT_MP_RESULT_K (ptr)++;
+ _REENT_MP_RESULT (ptr) = eBalloc (ptr, _REENT_MP_RESULT_K (ptr));
+ r = (char *) _REENT_MP_RESULT (ptr);
+
if (r == NULL)
return (
#ifndef MULTIPLE_THREADS
dtoa_result =
#endif
NULL);
- *r = k;
return
#ifndef MULTIPLE_THREADS
dtoa_result =
#endif
- (char *)(r+1);
+ r;
}
char *
freedtoa(struct _reent *ptr, char *s)
#endif
{
- Bigint *b = (Bigint *)((int *)s - 1);
- b->_maxwds = 1 << (b->_k = *(int*)b);
+ /* Free buffer allocated in a compatible way with legacy _ldtoa_r(). */
+ Bigint *b = (Bigint *)s;
+ b->_maxwds = 1 << (b->_k = _REENT_MP_RESULT_K (ptr));
Bfree(ptr, b);
#ifndef MULTIPLE_THREADS
if (s == dtoa_result)
/* reentrancy addition to use mprec storage pool */
if (_REENT_MP_RESULT (ptr)) {
- _REENT_MP_RESULT (ptr)->_k = _REENT_MP_RESULT_K (ptr);
- _REENT_MP_RESULT (ptr)->_maxwds = 1 << _REENT_MP_RESULT_K (ptr);
- Bfree (ptr, _REENT_MP_RESULT (ptr));
+ freedtoa (ptr, _REENT_MP_RESULT (ptr));
_REENT_MP_RESULT (ptr) = 0;
}
- Rename internal macros _NL_CTYPE_OUTDIGITSx_MB/WC to GLibc compatible
_NL_CTYPE_OUTDIGITx_MB/WC.
Addresses: https://cygwin.com/pipermail/cygwin-developers/2023-July/012637.html
+
+- Fix memory leak in printf() regarding gdtoa-based _ldtoa_r().
+ Addresses: https://cygwin.com/pipermail/cygwin/2023-July/254054.html