From 2edccb7f34a6381f00f96ad037230a5ff90fa626 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Sun, 13 Jul 2014 15:08:28 +0200 Subject: [PATCH] fast_atof: If a literal ends with a trailing dot (.), only parse further if the next character is a digit. In cases where the dot ends the literal (i.e. "1.") this would cause strtoul10_64 to throw an exception. To preserve as much of the old behaviour, we still consume trailing dots though. This "regression" was introduced (exposed) by #261, which added the extra check to strtoul10_64 that triggered here. This commit now fixes #304 (IFC file reading broken due to IFC files containing "(1.,1.,1.)" lists. --- code/fast_atof.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/code/fast_atof.h b/code/fast_atof.h index 5e6f5e4a5..ddda1f29e 100644 --- a/code/fast_atof.h +++ b/code/fast_atof.h @@ -231,13 +231,13 @@ inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma { Real f; - bool inv = (*c=='-'); - if (inv || *c=='+') { + bool inv = (*c == '-'); + if (inv || *c == '+') { ++c; } f = static_cast( strtoul10_64 ( c, &c) ); - if (*c == '.' || (check_comma && c[0] == ',' && c[1] >= '0' && c[1] <= '9')) // allow for commas, too + if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') { ++c; @@ -255,6 +255,10 @@ inline const char* fast_atoreal_move( const char* c, Real& out, bool check_comma pl *= fast_atof_table[diff]; f += static_cast( pl ); } + // For backwards compatibility: eat trailing dots, but not trailing commas. + else if (*c == '.') { + ++c; + } // A major 'E' must be allowed. Necessary for proper reading of some DXF files. // Thanks to Zhao Lei to point out that this if() must be outside the if (*c == '.' ..)