jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.43k stars 637 forks source link

Fix printf funcs on memory pressure with floats #1275

Closed GabrielRavier closed 2 months ago

GabrielRavier commented 2 months ago

Cosmopolitan's printf-family functions currently crash if one tries to format a floating point number with a large precision (large enough that gdtoa tries to allocate memory to format the number) when under memory pressure (i.e. when malloc fails), because gdtoa fails to check if malloc fails.

The added tests (which would previously crash under cosmopolitan without this patch) show how to reproduce the issue.

This patch fixes this, and adds the aforementioned tests.