Package: libpopt
Version: 1.16-1
The so-far undocumented (in the man pages) POPT_ARGFLAG_TOGGLE argument flag
somehow corrupts the values recovered by popt for some values of POPT_ARG_*,
specifically an integer of any width.
To demonstrate, first note that the "bps" line of the popt man pages example
reads:
{ "bps", 'b', POPT_ARG_INT, &speed, 0, "signaling rate in bits-per-second",
"BPS" },
Run 'parse --bps 2 silly' and then 'parse -b 2 silly'. In both cases you'll
get in part:
Options chosen: -b 2
Now change the poptOption entry to:
{ "bps", 'b', POPT_ARG_INT|POPT_ARG_TOGGLE, &speed, 0, "signaling rate in
bits-per-second", "BPS" },
Compile anew, then run 'parse --bps 2 silly', 'parse -b 2 silly' and 'parse
--nobps 2 silly'. In all three cases you'll get in part:
Options chosen: -b -3
This was expected only for the 'parse --nobps 2 silly' call, because -3 is
the two's-complement negation of 2.
Now change the poptOption entry to:
{ "bps", 'b', POPT_ARG_VAL, &speed, 2, "signaling rate in bits-per-second",
"BPS" },
Compile anew, then run 'parse --bps silly' and 'parse -b silly'. In all both
cases you'll get what you expect:
Options chosen: -b 2
Finally, change the poptOption entry to:
{ "bps", 'b', POPT_ARG_VAL|POPT_ARG_TOGGLE, &speed, 2, "signaling rate in
bits-per-second", "BPS" },
Compile anew, then run 'parse --bps silly', 'parse -b silly' and 'parse
--nobps silly'. In the first two cases you get the correct result (as above),
and the third is also as expected:
Options chosen: -b -3
The problem affects POPT_ARG_SHORT, POPT_ARG_INT, POPT_ARG_LONG,
POPT_ARG_LONGLONG. Not surprisingly, POPT_ARGFLAG_TOGGLE is ignored by
POPT_ARG_STRING, POPT_ARG_FLOAT, POPT_ARG_DOUBLE, etc.
I'm really puzzled by this bug, since the popt.c private helper function
poptArgInfo() ought to be the culprit but the argInfo bit-mangling part seems
correctly guarded.
Daniel U. Thibault
R & D pour la défense Canada - Valcartier (RDDC Valcartier) / Defence R&D
Canada - Valcartier (DRDC Valcartier)
Système de systèmes (SdS) / System of Systems (SoS)
Solutions informatiques et expérimentations (SIE) / Computing Solutions and
Experimentations (CSE)
2459 Boul. Pie XI Nord
Québec, QC G3J 1X5
CANADA
Vox : (418) 844-4000 x4245
Fax : (418) 844-4538
NAC: <http://www.travelgis.com/map.asp?addr=918V%20QSDJ> 918V QSDJ
Gouvernement du Canada / Government of Canada
< <http://www.valcartier.drdc-rddc.gc.ca/>
http://www.valcartier.drdc-rddc.gc.ca/>