fix/strict-integer-parsing #280
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds strict integer parsing for CLI arguments to prevent silent acceptance of malformed input. Previously, the CLI used
std::stoi/stoul/stoullwhich accepts trailing characters (e.g., "123abc" was silently parsed as 123). This fix ensures that invalid inputs are properly rejected with clear error messages.Fixes #225
Type of Change
Changes Made
New Utility Functions (cli/utils/util.h/cpp)
parseStrictInt()- Strict integer parsing with trailing character rejectionparseStrictULong()- Strict unsigned long parsingparseStrictULL()- Strict unsigned long long parsingAll functions throw
InvalidArgsExceptionwith descriptive error messages when:Replacements
cli/args/GlobalArgs.h- verbosity parameter parsingcli/args/BenchmarkArgs.h- level and numIters parameters (2 instances)cli/utils/compress_profiles.cpp- chunkSize parameter parsingcli/args/TrainArgs.h- threads, numSamples, maxTimeSecs, maxFileSizeMb, maxTotalSizeMb (5 instances)cli/args/CompressArgs.h- trainInlineTestLimit parameter parsingArchitecture Changes
ProfileArgsconstructor from header to .cpp to avoid circular dependenciesTest Plan
Manual Testing