Browse Source

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.

Alexander Gessler 11 years ago
parent
commit
2edccb7f34
1 changed files with 7 additions and 3 deletions
  1. 7 3
      code/fast_atof.h

+ 7 - 3
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<Real>( 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<Real>( 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 == '.' ..)