Modify

Ticket #12820 (new Bugs)

Opened 7 weeks ago

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: Cc:

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.

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.