diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-07-25 07:22:29 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-25 12:32:55 +0200 |
commit | 8c14219fb196262f05524a991d2d4c14ef653169 (patch) | |
tree | b065436c5088391243b7b8507fa229df9751f456 /AK/PrintfImplementation.h | |
parent | 9685080bd4e44080dbf7569f4b0e42ee890909a2 (diff) | |
download | serenity-8c14219fb196262f05524a991d2d4c14ef653169.zip |
AK: Fix print_double
Fixes #2776.
This fixes, among other things, JSON serialization.
The underlying bug was that 'print_double' defined fraction_length
as a function argument with a default value, whereas
printf_internal *always* provided a value, even if nothing was read.
The 'use 6 by default' logic has been moved to printf_internal instead.
Diffstat (limited to 'AK/PrintfImplementation.h')
-rw-r--r-- | AK/PrintfImplementation.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index 6f1b45d025..007b99d74f 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -178,7 +178,7 @@ ALWAYS_INLINE int print_u64(PutChFunc putch, char*& bufptr, u64 number, bool lef } template<typename PutChFunc> -ALWAYS_INLINE int print_double(PutChFunc putch, char*& bufptr, double number, bool left_pad, bool zero_pad, u32 field_width, u32 fraction_length = 6) +ALWAYS_INLINE int print_double(PutChFunc putch, char*& bufptr, double number, bool left_pad, bool zero_pad, u32 field_width, u32 fraction_length) { int length = 0; @@ -296,7 +296,8 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm bool zero_pad = false; bool dot = false; unsigned field_width = 0; - unsigned fraction_length = 0; + bool has_fraction_length = false; + unsigned fraction_length = 6; unsigned long_qualifiers = 0; bool size_qualifier = false; (void)size_qualifier; @@ -332,6 +333,10 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm if (*(p + 1)) goto one_more; } else { + if (!has_fraction_length) { + has_fraction_length = true; + fraction_length = 0; + } fraction_length *= 10; fraction_length += *p - '0'; if (*(p + 1)) |