Opened 6 years ago

Last modified 4 years ago

#12820 new Bugs

Unsigned value type accepts negative argument"'`--

Reported by: avogel@… Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.58.0 Severity: Problem
Keywords: 1 Cc: arachni@…

Description

In program_options, an option with e.g. value<std::uint32_t>() will accept negative arguments. A positional will not work without preceding -- because the minus sign is treated as the option character, though. So it's:

mycommand --foo-level -1

or

mycommand --foo-level=-1

or

mycommand -- -1

Assuming foo-level takes a std::uint32_t (and is the first positional option for the latter example), this will be accepted and converted to 4294967295 (aka UINT32_MAX). Likewise,

mycommand --foo-level -4294967196

will result in a value of 100. There's a workaround with a custom validator discussed at:

http://stackoverflow.com/questions/36800596/disallow-negative-argument-for-unsigned-value-with-boostprogram-options

But this should not be necessary IMO.

Change History (1)

in reply to:  1 ; comment:1 by arachni_name <arachni@…>, 4 years ago

Cc: arachni@… added
Keywords: 1 added
Summary: Unsigned value type accepts negative argumentUnsigned value type accepts negative argument"'`--

1

Note: See TracTickets for help on using tickets.