From a45880281a00d11c1cef7489741b8e59e2738d80 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 12 Jun 2006 06:36:36 +0000 Subject: [PATCH] Wrap strtof. Return 0 on nonfinite values. --- stepmania/src/RageUtil.cpp | 13 +++++++++++-- stepmania/src/RageUtil.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index bdbe529909..4e33254497 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -122,7 +122,7 @@ float HHMMSSToSeconds( const RString &sHHMMSS ) float fSeconds = 0; fSeconds += atoi( arrayBits[0] ) * 60 * 60; fSeconds += atoi( arrayBits[1] ) * 60; - fSeconds += strtof( arrayBits[2], NULL ); + fSeconds += StringToFloat( arrayBits[2] ); return fSeconds; } @@ -1472,6 +1472,15 @@ void MakeLower( wchar_t *p, size_t iLen ) UnicodeUpperLower( p, iLen, g_LowerCase ); } +float StringToFloat( const RString &sString ) +{ + float ret = strtof( sString, NULL ); + + if( !isfinite(ret) ) + ret = 0.0f; + return ret; +} + const wchar_t INVALID_CHAR = 0xFFFD; /* U+FFFD REPLACEMENT CHARACTER */ wstring RStringToWstring( const RString &s ) @@ -1964,7 +1973,7 @@ bool FileRead( RageFileBasic& f, float& fOut ) RString s; if( !FileRead(f, s) ) return false; - fOut = strtof( s, NULL ); + fOut = StringToFloat( s ); return true; } diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 7354eb4197..919b40ac4e 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -292,6 +292,7 @@ void MakeUpper( char *p, size_t iLen ); void MakeLower( char *p, size_t iLen ); void MakeUpper( wchar_t *p, size_t iLen ); void MakeLower( wchar_t *p, size_t iLen ); +float StringToFloat( const RString &sString ); RString WStringToRString( const wstring &sString ); RString WcharToUTF8( wchar_t c );