From 3e55dca943d829e6045fb3d696ce4411c70abe43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Terziman?= Date: Mon, 25 Nov 2013 11:22:31 +0100 Subject: [PATCH] Improved fast_atof --- code/fast_atof.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/fast_atof.h b/code/fast_atof.h index a10ee9666..2a44c4f03 100644 --- a/code/fast_atof.h +++ b/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;