Reject negative input and partial parsing for unsigned argument types#135
Merged
Taywee merged 2 commits intoTaywee:masterfrom Apr 20, 2026
Merged
Conversation
Owner
|
Feels a bit hacky, but that's the best you can really get when you're working with C++ iostreams. Unfortunately, this does cause other unrelated tests to start failing: taylor@project-zeus> make runtests
g++ test.cxx -o test.o -I. -std=c++11 -O0 -c -MMD -Wall -Wextra -Wno-unused-parameter -Werror -pedantic
g++ -o argstest test.o -std=c++11 -O0
./argstest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
argstest is a Catch v2.13.7 host application.
Run with -? for options
-------------------------------------------------------------------------------
Argument flags work as expected, with clustering
-------------------------------------------------------------------------------
test.cxx:67
...............................................................................
test.cxx:67: FAILED:
due to unexpected exception with message:
Argument 'BAZ' received invalid value type '7.555e2'
-------------------------------------------------------------------------------
Unified argument lists for match work
-------------------------------------------------------------------------------
test.cxx:93
...............................................................................
test.cxx:93: FAILED:
due to unexpected exception with message:
Argument 'BAZ' received invalid value type '7.555e2'
-------------------------------------------------------------------------------
Argument flag lists work as expected
-------------------------------------------------------------------------------
test.cxx:142
...............................................................................
test.cxx:142: FAILED:
due to unexpected exception with message:
Argument 'FOO' received invalid value type '7'
-------------------------------------------------------------------------------
Argument flag lists replace default values
-------------------------------------------------------------------------------
test.cxx:158
...............................................................................
test.cxx:158: FAILED:
due to unexpected exception with message:
Argument 'FOO' received invalid value type '7'
-------------------------------------------------------------------------------
Positional lists work as expected
-------------------------------------------------------------------------------
test.cxx:166
...............................................................................
test.cxx:166: FAILED:
due to unexpected exception with message:
Argument 'FOO' received invalid value type '7'
-------------------------------------------------------------------------------
Positional lists replace default values
-------------------------------------------------------------------------------
test.cxx:182
...............................................................................
test.cxx:182: FAILED:
due to unexpected exception with message:
Argument 'FOO' received invalid value type '7'
-------------------------------------------------------------------------------
Positional arguments and positional argument lists work as expected
-------------------------------------------------------------------------------
test.cxx:200
...............................................................................
test.cxx:200: FAILED:
due to unexpected exception with message:
Argument 'BAR' received invalid value type '0'
-------------------------------------------------------------------------------
The option terminator works as expected
-------------------------------------------------------------------------------
test.cxx:215
...............................................................................
test.cxx:215: FAILED:
due to unexpected exception with message:
Argument 'BAR' received invalid value type '0'
-------------------------------------------------------------------------------
Custom types work
-------------------------------------------------------------------------------
test.cxx:355
...............................................................................
test.cxx:361: FAILED:
{Unknown expression after the reported line}
due to unexpected exception with message:
Argument 'INTS' received invalid value type '1,2'
-------------------------------------------------------------------------------
Custom parser prefixes (dd-style)
-------------------------------------------------------------------------------
test.cxx:373
...............................................................................
test.cxx:373: FAILED:
due to unexpected exception with message:
Argument 'BYTES' received invalid value type '8'
-------------------------------------------------------------------------------
Custom parser prefixes (Some Windows styles)
-------------------------------------------------------------------------------
test.cxx:393
...............................................................................
test.cxx:393: FAILED:
due to unexpected exception with message:
Argument 'BYTES' received invalid value type '8'
-------------------------------------------------------------------------------
Help menu can be grabbed as a string, passed into a stream, or by using the
overloaded stream operator
-------------------------------------------------------------------------------
test.cxx:413
...............................................................................
test.cxx:413: FAILED:
due to unexpected exception with message:
Argument 'BYTES' received invalid value type '8'
-------------------------------------------------------------------------------
Required flags work as expected
-------------------------------------------------------------------------------
test.cxx:623
...............................................................................
test.cxx:623: FAILED:
due to unexpected exception with message:
Argument 'foo' received invalid value type '42'
-------------------------------------------------------------------------------
Implicit values work as expected
-------------------------------------------------------------------------------
test.cxx:663
...............................................................................
test.cxx:671: FAILED:
REQUIRE_NOTHROW( parser.ParseArgs(std::vector<std::string>{"-j4"}) )
due to unexpected exception with message:
Argument 'parallel' received invalid value type '4'
-------------------------------------------------------------------------------
Nargs work as expected
-------------------------------------------------------------------------------
test.cxx:686
...............................................................................
test.cxx:697: FAILED:
REQUIRE_NOTHROW( parser.ParseArgs(std::vector<std::string>{"-a", "1", "2"}) )
due to unexpected exception with message:
Argument '' received invalid value type '1'
-------------------------------------------------------------------------------
ValueParser works as expected
-------------------------------------------------------------------------------
test.cxx:1197
...............................................................................
test.cxx:1217: FAILED:
REQUIRE_NOTHROW( p.ParseArgs(std::vector<std::string>{"-i", " 12"}) )
due to unexpected exception with message:
Argument 'name' received invalid value type ' 12'
-------------------------------------------------------------------------------
Noexcept mode works as expected
-------------------------------------------------------------------------------
test.cxx:1378
...............................................................................
test.cxx:1418: FAILED:
REQUIRE( parser.GetError() == argstest::Error::None )
with expansion:
2 == 0
-------------------------------------------------------------------------------
Required flags work as expected in noexcept mode
-------------------------------------------------------------------------------
test.cxx:1452
...............................................................................
test.cxx:1460: FAILED:
REQUIRE( parser1.GetError() == argstest::Error::None )
with expansion:
2 == 0
===============================================================================
test cases: 60 | 42 passed | 18 failed
assertions: 260 | 242 passed | 18 failed |
Taywee
requested changes
Apr 18, 2026
Owner
Taywee
left a comment
There was a problem hiding this comment.
Tests are failing now and need to be fixed.
make runtests is usually the easiest way to run them.
Taywee
approved these changes
Apr 20, 2026
Owner
Taywee
left a comment
There was a problem hiding this comment.
That looks good to me now, and tests now pass.
Owner
|
Thank you for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This patch fixes a parsing flaw in ValueReader where invalid numeric input could be silently accepted.
Issues addressed:
Negative values for unsigned types:
Inputs such as "-1" were previously accepted and converted via
wraparound (e.g., to UINT_MAX), which can bypass validation logic
in downstream applications.
Partial numeric parsing:
Inputs like "123abc" were partially parsed as 123 and accepted,
ignoring trailing invalid characters.
Fix: