Fixing a rare bug when parsing floating-point numbers in exponent form. Thanks to zhao lei to point it out.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@388 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
f0ca5b8a56
commit
acdbf77c6e
5
CREDITS
5
CREDITS
|
@ -13,7 +13,7 @@ Thanks for your help!
|
||||||
Configuration-Interface, AssImp-Viewer (Win32), Website (Admin and Design), admin.
|
Configuration-Interface, AssImp-Viewer (Win32), Website (Admin and Design), admin.
|
||||||
|
|
||||||
-Thomas Schulze,
|
-Thomas Schulze,
|
||||||
X-, Collda-, BVH-Loader, Postprocessing framework. Data structure & Interface design, documentation.
|
X-, Collada-, BVH-Loader, Postprocessing framework. Data structure & Interface design, documentation.
|
||||||
|
|
||||||
-R.Schmidt,
|
-R.Schmidt,
|
||||||
Linux build, eclipse support.
|
Linux build, eclipse support.
|
||||||
|
@ -58,3 +58,6 @@ The GUY who performed some of the CSM mocaps.
|
||||||
|
|
||||||
- Andy Maloney
|
- Andy Maloney
|
||||||
Contributed fixes for the documentation and the doxygen markup
|
Contributed fixes for the documentation and the doxygen markup
|
||||||
|
|
||||||
|
- Zhao Lei
|
||||||
|
Contributed several bugfixes fixing memory leaks and improving float parsing
|
||||||
|
|
|
@ -41,7 +41,7 @@ const float fast_atof_table[16] = { // we write [16] here instead of [] to work
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
// convert a string in decimal format to a number
|
// Convert a string in decimal format to a number
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
inline unsigned int strtol10( const char* in, const char** out=0)
|
inline unsigned int strtol10( const char* in, const char** out=0)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ inline unsigned int strtol10( const char* in, const char** out=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
// convert a string in octal format to a number
|
// Convert a string in octal format to a number
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
inline unsigned int strtol8( const char* in, const char** out=0)
|
inline unsigned int strtol8( const char* in, const char** out=0)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ inline unsigned int strtol8( const char* in, const char** out=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
// convert a string in hex format to a number
|
// Convert a string in hex format to a number
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
inline unsigned int strtol16( const char* in, const char** out=0)
|
inline unsigned int strtol16( const char* in, const char** out=0)
|
||||||
{
|
{
|
||||||
|
@ -165,8 +165,8 @@ inline unsigned int strtol_cppstyle( const char* in, const char** out=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
// Special version of the function, providing higher accuracy and security
|
// Special version of the function, providing higher accuracy and safety
|
||||||
// It is mainly used bx fast_atof to prevent ugly integer overflows.
|
// It is mainly used by fast_atof to prevent ugly and unwanted integer overflows.
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
inline uint64_t strtol10_64( const char* in, const char** out=0, unsigned int* max_inout=0)
|
inline uint64_t strtol10_64( const char* in, const char** out=0, unsigned int* max_inout=0)
|
||||||
{
|
{
|
||||||
|
@ -180,7 +180,7 @@ inline uint64_t strtol10_64( const char* in, const char** out=0, unsigned int* m
|
||||||
|
|
||||||
const uint64_t new_value = ( value * 10 ) + ( *in - '0' );
|
const uint64_t new_value = ( value * 10 ) + ( *in - '0' );
|
||||||
|
|
||||||
if (new_value < value) /* numeric overflow */
|
if (new_value < value) /* numeric overflow, we rely on you */
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
value = new_value;
|
value = new_value;
|
||||||
|
@ -191,7 +191,8 @@ inline uint64_t strtol10_64( const char* in, const char** out=0, unsigned int* m
|
||||||
if (max_inout && *max_inout == cur) {
|
if (max_inout && *max_inout == cur) {
|
||||||
|
|
||||||
if (out) { /* skip to end */
|
if (out) { /* skip to end */
|
||||||
while (*in >= '0' && *in <= '9')++in;
|
while (*in >= '0' && *in <= '9')
|
||||||
|
++in;
|
||||||
*out = in;
|
*out = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +208,7 @@ inline uint64_t strtol10_64( const char* in, const char** out=0, unsigned int* m
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Number of relevant decimals for floating-point parsing.
|
||||||
#define AI_FAST_ATOF_RELAVANT_DECIMALS 6
|
#define AI_FAST_ATOF_RELAVANT_DECIMALS 6
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
|
@ -216,46 +218,42 @@ inline uint64_t strtol10_64( const char* in, const char** out=0, unsigned int* m
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
inline const char* fast_atof_move( const char* c, float& out)
|
inline const char* fast_atof_move( const char* c, float& out)
|
||||||
{
|
{
|
||||||
bool inv = false;
|
|
||||||
const char *t;
|
const char *t;
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
if (*c=='-')
|
bool inv = (*c=='-');
|
||||||
{
|
if (inv || *c=='+')
|
||||||
++c;
|
++c;
|
||||||
inv = true;
|
|
||||||
}
|
|
||||||
else if (*c=='+')++c;
|
|
||||||
|
|
||||||
f = (float) strtol10_64 ( c, &c );
|
f = (float) strtol10_64 ( c, &c );
|
||||||
if (*c == '.' || (c[0] == ',' && isdigit( c[1])))
|
if (*c == '.' || (c[0] == ',' && (c[1] >= '0' || c[1] <= '9'))) // allow for commas, too
|
||||||
{
|
{
|
||||||
++c;
|
++c;
|
||||||
|
|
||||||
// NOTE: The original implementation is highly unaccurate here
|
// NOTE: The original implementation is highly unaccurate here. The precision of a single
|
||||||
// The precision of a single IEEE 754 float is not high enough
|
// IEEE 754 float is not high enough, everything behind the 6th digit tends to be more
|
||||||
// everything behind the 6th digit tends to be more inaccurate
|
// inaccurate than it would need to be. Casting to double seems to solve the problem.
|
||||||
// than it would need to be.
|
|
||||||
// Casting to double seems to solve the problem.
|
|
||||||
// strtol_64 is used to prevent integer overflow.
|
// strtol_64 is used to prevent integer overflow.
|
||||||
|
|
||||||
// Another fix: this tends to become 0 if we don't limit
|
// Another fix: this tends to become 0 for long numbers if we don't limit the maximum
|
||||||
// the maximum number of digits
|
// number of digits to be read. AI_FAST_ATOF_RELAVANT_DECIMALS can be a value between
|
||||||
|
// 1 and 15.
|
||||||
unsigned int diff = AI_FAST_ATOF_RELAVANT_DECIMALS;
|
unsigned int diff = AI_FAST_ATOF_RELAVANT_DECIMALS;
|
||||||
double pl = (double) strtol10_64 ( c, &t, &diff );
|
double pl = (double) strtol10_64 ( c, &t, &diff );
|
||||||
|
|
||||||
pl *= fast_atof_table[diff];
|
pl *= fast_atof_table[diff];
|
||||||
|
|
||||||
f += (float)pl;
|
f += (float)pl;
|
||||||
|
|
||||||
c = t;
|
c = t;
|
||||||
|
}
|
||||||
|
|
||||||
// FIX: a large 'E' should be allowed, too (occurs in some DXF files)
|
// 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 == '.' ..)
|
||||||
if (*c == 'e' || *c == 'E')
|
if (*c == 'e' || *c == 'E')
|
||||||
{
|
{
|
||||||
++c;
|
++c;
|
||||||
bool einv = (*c=='-');
|
bool einv = (*c=='-');
|
||||||
if (einv)
|
if (einv || *c=='+')
|
||||||
++c;
|
++c;
|
||||||
|
|
||||||
float exp = (float)strtol10(c, &c);
|
float exp = (float)strtol10(c, &c);
|
||||||
|
@ -264,7 +262,6 @@ inline const char* fast_atof_move( const char* c, float& out)
|
||||||
|
|
||||||
f *= pow(10.0f, exp);
|
f *= pow(10.0f, exp);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (inv)
|
if (inv)
|
||||||
f *= -1.0f;
|
f *= -1.0f;
|
||||||
|
@ -275,6 +272,7 @@ inline const char* fast_atof_move( const char* c, float& out)
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
|
// The same but more human.
|
||||||
inline float fast_atof(const char* c)
|
inline float fast_atof(const char* c)
|
||||||
{
|
{
|
||||||
float ret;
|
float ret;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define SVNRevision 377
|
#define SVNRevision 387
|
||||||
|
|
|
@ -2275,26 +2275,6 @@
|
||||||
RelativePath="..\..\code\BaseProcess.h"
|
RelativePath="..\..\code\BaseProcess.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\ByteSwap.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\fast_atof.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\GenericProperty.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\Hash.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\IFF.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\code\Importer.cpp"
|
RelativePath="..\..\code\Importer.cpp"
|
||||||
>
|
>
|
||||||
|
@ -2307,14 +2287,6 @@
|
||||||
RelativePath="..\..\code\MaterialSystem.h"
|
RelativePath="..\..\code\MaterialSystem.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\ParsingUtils.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\qnan.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\code\RemoveComments.cpp"
|
RelativePath="..\..\code\RemoveComments.cpp"
|
||||||
>
|
>
|
||||||
|
@ -2379,10 +2351,6 @@
|
||||||
RelativePath="..\..\code\StandardShapes.h"
|
RelativePath="..\..\code\StandardShapes.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\code\StringComparison.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\code\TargetAnimation.cpp"
|
RelativePath="..\..\code\TargetAnimation.cpp"
|
||||||
>
|
>
|
||||||
|
@ -3404,6 +3372,42 @@
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="util"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\ByteSwap.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\fast_atof.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\GenericProperty.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\Hash.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\IFF.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\ParsingUtils.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\qnan.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\code\StringComparison.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="doc"
|
Name="doc"
|
||||||
|
|
Loading…
Reference in New Issue