diff --git a/src/tools/disco/Character.hpp b/src/tools/disco/Character.hpp index 7360326..2d9236d 100644 --- a/src/tools/disco/Character.hpp +++ b/src/tools/disco/Character.hpp @@ -38,9 +38,13 @@ class Character : public BaseFixedWidthField< Width > { * @param[in,out] iter an iterator to a character in a range */ template < typename Representation, typename Iterator > - static Representation read( Iterator& iter, const Iterator& ) { + static Representation read( Iterator& iter, const Iterator& end ) { Representation value; + if ( iter >= end ) { + + return value; + } value.reserve( Width ); unsigned int position = 0; diff --git a/src/tools/disco/Column.hpp b/src/tools/disco/Column.hpp index 6f7310e..255e081 100644 --- a/src/tools/disco/Column.hpp +++ b/src/tools/disco/Column.hpp @@ -37,10 +37,10 @@ class Column : public BaseFixedWidthField< Width > { * @param[in,out] iter an iterator to a character in a range */ template < typename Iterator > - static void read( Iterator& iter, const Iterator& ) { + static void read( Iterator& iter, const Iterator& end ) { unsigned int position = 0; - while( position < Width && ! ( isNewLine( iter ) || isEndOfFile( iter ) ) ) { + while( position < Width && ! ( isNewLine( iter ) || isEndOfFile( iter ) || iter >= end ) ) { ++position; ++iter; diff --git a/src/tools/disco/Integer.hpp b/src/tools/disco/Integer.hpp index cdef43b..6d2333d 100644 --- a/src/tools/disco/Integer.hpp +++ b/src/tools/disco/Integer.hpp @@ -41,14 +41,14 @@ class Integer : public BaseFixedWidthField< Width > { * @param[in,out] iter an iterator to a character in a range */ template < typename Representation, typename Iterator > - static Representation read( Iterator& iter, const Iterator& ) { + static Representation read( Iterator& iter, const Iterator& end ) { unsigned int position = 0; - const auto end = iter + Width; + const auto final = iter + Width; Representation value = 0; skipSpaces( iter, position ); - if ( isNewLine( iter ) || isEndOfFile( iter ) || Width == position ) { + if ( isNewLine( iter ) || isEndOfFile( iter ) || Width == position || iter >= end ) { return value; } @@ -62,7 +62,7 @@ class Integer : public BaseFixedWidthField< Width > { // we are using fast_float::from_chars instead of std::from_chars since // not all standard c++ libraries implement the floating point version of // std::from_chars - auto result = fast_float::from_chars( &*iter, &*end, value ); + auto result = fast_float::from_chars( &*iter, &*final, value ); if ( result.ec == std::errc() ) { auto advance = result.ptr - &*iter; diff --git a/src/tools/disco/Real.hpp b/src/tools/disco/Real.hpp index 107f19b..f28ee53 100644 --- a/src/tools/disco/Real.hpp +++ b/src/tools/disco/Real.hpp @@ -33,14 +33,14 @@ class Real : public BaseFixedWidthField< Width > { * @param[in,out] iter an iterator to a character in a range */ template < typename Representation, typename Iterator > - static Representation read( Iterator& iter, const Iterator& ) { + static Representation read( Iterator& iter, const Iterator& end ) { unsigned int position = 0; - const auto end = iter + Width; + const auto final = iter + Width; Representation value = 0.0; skipSpaces( iter, position ); - if ( isNewLine( iter ) || isEndOfFile( iter ) || Width == position ) { + if ( isNewLine( iter ) || isEndOfFile( iter ) || Width == position || iter >= end ) { return value; } @@ -56,7 +56,7 @@ class Real : public BaseFixedWidthField< Width > { // of std::from_chars and because this allows us to read fortran formatted // floats fast_float::parse_options options{ fast_float::chars_format::fortran }; - auto result = fast_float::from_chars_advanced( &*iter, &*end, value, options ); + auto result = fast_float::from_chars_advanced( &*iter, &*final, value, options ); if ( result.ec == std::errc() ) { auto advance = result.ptr - &*iter;