Skip to content

Commit ba911c1

Browse files
committed
Merge branch 'master' of github.com:sandialabs/SpecUtils
2 parents 5211de2 + 9ca121d commit ba911c1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/SpecFile_phd.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ bool SpecFile::load_from_phd( std::istream &input )
162162

163163
const float upper_energy = (fields.size()>1 && fields[1]>500.0f && fields[1]<13000.0f) ? fields[1] : 0.0f;
164164
const size_t nchannel = static_cast<size_t>( fields[0] );
165-
auto counts = std::make_shared< vector<float> >(nchannel,0.0f);
165+
if( (nchannel < 1) || (nchannel > 1024*65536) )
166+
throw runtime_error( "Invalid number of channels (" + std::to_string(nchannel) + ")" );
166167

168+
auto counts = std::make_shared< vector<float> >(nchannel,0.0f);
167169

168170
size_t last_channel = 0;
169171
while( SpecUtils::safe_get_line(input, line, max_len) )
@@ -187,7 +189,7 @@ bool SpecFile::load_from_phd( std::istream &input )
187189

188190
const size_t start_channel = static_cast<size_t>( fields[0] );
189191

190-
if( (start_channel <= last_channel) || (start_channel > nchannel) )
192+
if( (last_channel != 0) && ((start_channel <= last_channel) || (start_channel > nchannel)) )
191193
throw runtime_error( "Channels not ordered as expected" );
192194

193195
//We'll let the fuzzing test give us out-of-order channels, but otherwise require the file
@@ -269,9 +271,9 @@ bool SpecFile::load_from_phd( std::istream &input )
269271
measurements_.push_back( meas );
270272

271273
cleanup_after_load();
272-
}catch( std::exception & )
274+
}catch( std::exception &e )
273275
{
274-
//cerr << SRC_LOCATION << "caught: " << e.what() << endl;
276+
cerr << "caught: " << e.what() << endl;
275277
reset();
276278
input.clear();
277279
input.seekg( orig_pos, ios::beg );

0 commit comments

Comments
 (0)