Fix trailing whitespace problem.

sscanf() returns EOF when it reaches the end of the string. Our code
erroneously interprets this as if a number was read. The fix: we test for an
explicit '1'.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Mooffie 2016-09-25 17:24:44 +03:00 committed by Andrew Borodin
parent b25af93874
commit cc8fcdcfc0
2 changed files with 3 additions and 3 deletions

View File

@ -85,7 +85,7 @@ mc_search__hex_translate_to_regex (const GString * astr, mc_search_hex_parse_err
int ptr; int ptr;
/* cppcheck-suppress invalidscanf */ /* cppcheck-suppress invalidscanf */
if (sscanf (tmp_str + loop, "%x%n", &val, &ptr)) if (sscanf (tmp_str + loop, "%x%n", &val, &ptr) == 1)
{ {
if (val > 255) if (val > 255)
error = MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE; error = MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE;

View File

@ -56,8 +56,8 @@ static const struct test_hex_translate_to_regex_ds
MC_SEARCH_HEX_E_OK MC_SEARCH_HEX_E_OK
}, },
{ {
/* Extra whitespace (but not trailing one) */ /* Extra whitespace */
" 12 34", " 12 34 ",
"\\x12\\x34", "\\x12\\x34",
MC_SEARCH_HEX_E_OK MC_SEARCH_HEX_E_OK
}, },