From 0eb88fafd4afcf1fb3dda11c405c396fa5b68466 Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Wed, 20 May 2026 19:41:06 +0530 Subject: [PATCH] Avoid relying on peek()-after-failbit semantics in ParseNumericValue --- args.hxx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/args.hxx b/args.hxx index f38cac4..4c9413c 100644 --- a/args.hxx +++ b/args.hxx @@ -3922,8 +3922,22 @@ namespace args return false; } - ss >> std::ws; - return ss.peek() == std::char_traits::eof(); + // Check for trailing garbage by attempting to extract any remaining characters. + // Do not use 'ss >> std::ws' followed by peek(), as std::ws can set failbit + // on EOF, causing false rejection of valid input. + char extra = '\0'; + ss >> std::ws >> extra; + // If extraction succeeded, there's trailing garbage (return false). + // If extraction failed due to EOF only (goodbit after ws extraction), it's valid (return true). + // If extraction failed for other reasons, it's invalid (return false). + if (ss.fail()) + { + // Clear the failbit to check if EOF is the only issue + ss.clear(ss.rdstate() & ~std::ios::failbit); + return ss.eof(); + } + // Extraction succeeded, meaning there's trailing garbage + return false; } template