From cea6cf8a5e87127eccc8214cbffa2d4c8aae8527 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 15 Mar 2016 12:21:56 +0000 Subject: py/formatfloat: Fix buffer overflow when formatting tiny numbers. --- tests/float/string_format_modulo.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/float') diff --git a/tests/float/string_format_modulo.py b/tests/float/string_format_modulo.py index 03b178703..681e9eb80 100644 --- a/tests/float/string_format_modulo.py +++ b/tests/float/string_format_modulo.py @@ -26,3 +26,19 @@ print("%02.3d" % 123) # prec > width print("%+f %+f" % (1.23, -1.23)) # float sign print("% f % f" % (1.23, -1.23)) # float space sign print("%0f" % -1.23) # negative number with 0 padding + +# numbers with large negative exponents +print('%f' % 1e-10) +print('%f' % 1e-20) +print('%f' % 1e-50) +print('%f' % 1e-100) +print('%f' % 1e-300) + +# large decimal precision should be truncated and not overflow buffer +# the output depends on the FP calculation so only first 2 digits are printed +# (the 'g' with small e are printed using 'f' style, so need to be checked) +print(('%.40f' % 1e-300)[:2]) +print(('%.40g' % 1e-1)[:2]) +print(('%.40g' % 1e-2)[:2]) +print(('%.40g' % 1e-3)[:2]) +print(('%.40g' % 1e-4)[:2]) -- cgit v1.2.3