Boost logo

Boost :

From: Matt Borland (matt_at_[hidden])
Date: 2024-01-17 10:38:53


>

> > There are 2 uses of malloc. 1 is behind BOOST_CHARCONV_DEBUG used for printing 128-bit integer strings in ryu_generic_128. The other could in an extreme edge case be hit by the user. It is used in a fallback routine in case of unsuccessful 80 or 128 bit long double conversions in from_chars. If the conversion is unsuccessful on first attempt, and the string is more than 1024 bytes then we need to malloc to avoid a buffer overrun. The rationale for malloc is that it won't throw of failure.
>

>

> Under which conditions would this happen? Could you please provide an example?
>

With arbitrary precision floats, e.g. GMP's mpf_t, it is not uncommon to dump the representation to char* using mpf_get_str. Say it had 1100 digits of what would be a 128-bit subnormal number then you would hit this edge case.

Matt






Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk