Check number syntax is valid in hts_parse_decimal() #1400
Merged
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.
Motivated by #1395, this alters
hts_parse_decimal()
to validate that the number parsed is indeed a validly presented numeric value and to have a way of reporting failure. What we want to accept and the returnedstrend
value are carefully considered, and test cases are added accordingly.Follows
strtol()
et al's conventions, settingstrend
to the originalstr
(or emitting a warning ifstrend
is NULL) if the input string does not form a valid numeric constant. In particular, require it to have a non-zero number of digits.Merges E and k/M/G handling, so that at most one can be used. In particular, "1e+3k" is non-standard and ambiguous, and should be rejected.
Adds documentation to htslib/hts.h describing the numeric syntax parsed and the two modes of operation (as determined by whether
strend
is NULL or not).Add test cases, in particular verifying that a sole "G" is rejected. Fixes #1395. For simplicity, the tests are added to test/sam.c which already contains similar API tests. If preferred, I could create a new test/hts.c containing these tests instead.