From 8a91559895ca3d5dc6d3b56d673ab5245372bf01 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 22 Jun 2026 19:13:38 +0200 Subject: [PATCH] Fix infinite loop loading non-scenery files (e.g. .fiz) via cParser The buffer-based tokenizer reads the source into memory once at construction, so the underlying stream fail bit never flips at end-of-input. cParser::ok() was not stream.fail(), so while( parser.ok() ) loops (TMoverParameters::LoadFIZ and similar) never terminated -- they spun on empty tokens past EOF, hanging the vehicle/.fiz load. Redefine ok() as "input still remains" (buffer not exhausted, or for replay not exhausted), which terminates those loops while staying true right after opening a non-empty file (the open checks if(!ok())). Co-Authored-By: Claude Opus 4.8 --- utilities/parser.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utilities/parser.h b/utilities/parser.h index 4b102aab..607781a7 100644 --- a/utilities/parser.h +++ b/utilities/parser.h @@ -82,7 +82,14 @@ class cParser //: public std::stringstream inline bool ok() { - return ( !mStream->fail() ); }; + // historically !stream.fail(); with the in-memory buffer the stream is read + // only once at construction, so its fail bit never flips at end-of-input. + // ok() now means "there is still input to read", which is what the common + // `while( parser.ok() )` loops rely on, and is true right after opening a + // non-empty file (the `if( !ok() )` open checks) / false if the open failed + // (empty buffer) or once everything has been consumed. + if( m_replay ) { return ( false == m_replayexhausted ); } + return ( m_bufferpos < m_buffer.size() ); }; cParser & autoclear( bool const Autoclear ); inline