Skip to content

Reject empty strings as double argument values - #158

Merged
tomghuang merged 1 commit into
argtable:masterfrom
fhgffy:fix/reject-empty-double-values
Oct 5, 2026
Merged

tomghuang merged 1 commit into
argtable:masterfrom
fhgffy:fix/reject-empty-double-values

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

An explicit empty short-option value (-d "") or positional argument is currently accepted as the double value 0. strtod returns zero without consuming any characters, but arg_dbl_scanfn only checks whether the end pointer points to the string terminator.

Require the conversion to consume characters before storing the value. Empty input now follows the existing invalid-double error path without changing the stored default or argument count. Omitted optional values retain their current behavior. Long options already report a missing-argument error for an explicit empty value; the double scanner now also rejects that value, consistent with the integer scanner.

Six tests cover short and positional empty values, explicit long-option values, omitted versus empty optional values, repeated arguments, valid zero/negative/exponent values, and neighboring invalid inputs. Five of these tests fail on the original code; the conversion controls pass.

Validation on Linux with GCC 14.2.0 and CMake 3.31.6:

  • Debug and Release: static library, individual sources, and generated amalgamation tests pass
  • Shared Debug, system getopt, and long-only configurations: all three CTest targets pass in each configuration
  • ASan/UBSan: all three CTest targets pass with leak detection disabled
  • Installed CMake package consumer passes the empty-value regression
  • A separate 29-assertion parser/callback test passes with bundled getopt, system getopt, and LONG_ONLY; the original code fails eight empty-input assertions in each configuration

The full static/source/amalgamation suite contains 176 tests; the shared-library suite contains 169. The amalgamation was regenerated before compiling. Its line-ending normalization command (dos2unix) is unavailable in this environment; generation, compilation, and tests completed with the existing line endings. Clang, Windows/MSVC, Valgrind, and LeakSanitizer were not tested.

@fhgffy
fhgffy marked this pull request as ready for review October 4, 2026 22:16
@tomghuang
tomghuang merged commit 8137dff into argtable:master Oct 5, 2026
12 checks passed
@tomghuang

Copy link
Copy Markdown
Contributor

@fhgffy: Really appreciate your patch to correct the behavior. All the pipeline checks passed, so I'll merge it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants