Skip to content

Commit

Permalink
Merge branch 'fix/guards' into 'develop'
Browse files Browse the repository at this point in the history
Adding some guards to fix an ENDFtk issue

See merge request njoy/tools!3
  • Loading branch information
whaeck committed Oct 15, 2024
2 parents 0d41b69 + 6622320 commit 6ab7fc8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/tools/disco/Character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/disco/Column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/tools/disco/Integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/tools/disco/Real.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 6ab7fc8

Please sign in to comment.