@@ -38,17 +38,31 @@ class FreeFormatReal : public BaseField {
3838
3939 Representation value = 0 ;
4040
41+ // copy the start before find_if modifies iter
42+ auto start = iter;
43+
4144 iter = std::find_if ( iter, end,
4245 [] ( auto && value )
4346 { return ! std::isspace ( value ); } );
4447
48+ // if the value is not in the string, find_if returns the end of the range, in
49+ // which case msvc will not allow dereferencing iter. So, throw a runtime
50+ // error here in that case:
51+ if ( iter == end ) {
52+
53+ std::string message ( &*start, &*std::prev ( end ) + 1 );
54+ message.insert ( 0 , " Could not read valid real value: " );
55+ message += ' \" ' ;
56+ throw std::runtime_error ( message );
57+ }
58+
4559 // we are using fast_float::from_chars_advanced instead of std::from_chars
4660 // since not all standard c++ libraries implement the floating point version
4761 // of std::from_chars and because this allows us to read fortran formatted
4862 // floats
4963 if ( *iter == ' +' ) { ++iter; }
5064 fast_float::parse_options options{ fast_float::chars_format::fortran };
51- auto result = fast_float::from_chars_advanced ( &*iter, &*end, value, options );
65+ auto result = fast_float::from_chars_advanced ( &*iter, &*std::prev ( end ) + 1 , value, options );
5266 if ( result.ec == std::errc () ) {
5367
5468 auto advance = result.ptr - &*iter;
0 commit comments