소스 검색

Improved fast_atof

Léo Terziman 11 년 전
부모
커밋
3e55dca943
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      code/fast_atof.h

+ 4 - 1
code/fast_atof.h

@@ -179,6 +179,9 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int*
 	unsigned int cur = 0;
 	uint64_t value = 0;
 
+	if ( *in < '0' || *in > '9' )
+			throw std::invalid_argument(std::string("The string \"") + in + "\" cannot be converted into a value.");
+
 	bool running = true;
 	while ( running )
 	{
@@ -188,7 +191,7 @@ inline uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int*
 		const uint64_t new_value = ( value * 10 ) + ( *in - '0' );
 		
 		if (new_value < value) /* numeric overflow, we rely on you */
-			return value;
+			throw std::overflow_error(std::string("Converting the string \"") + in + "\" into a value resulted in overflow.");
 
 		value = new_value;