LibC: Do not include suppressed assignments in scanf return value

This commit is contained in:
Peter Ross 2022-02-14 17:04:01 +11:00 committed by Ali Mohammad Pur
parent 7b0f3b6811
commit 31079a56d7
Notes: sideshowbarker 2024-07-17 21:16:31 +09:00
2 changed files with 11 additions and 10 deletions

View file

@ -178,6 +178,7 @@ const TestSuite test_suites[] {
{ "%llu", "9223372036854775810", 1, 1, { unsignedlonglongarg0 }, { to_value_t(9223372036854775810ULL) } }, { "%llu", "9223372036854775810", 1, 1, { unsignedlonglongarg0 }, { to_value_t(9223372036854775810ULL) } },
{ "%n", "", 0, 1, { intarg0 }, { to_value_t(0) } }, { "%n", "", 0, 1, { intarg0 }, { to_value_t(0) } },
{ "%d %n", "1 a", 1, 2, { intarg0, intarg1 }, { to_value_t(1), to_value_t(2) } }, { "%d %n", "1 a", 1, 2, { intarg0, intarg1 }, { to_value_t(1), to_value_t(2) } },
{ "%*d", " 42", 0, 0, {}, {} },
}; };
bool g_any_failed = false; bool g_any_failed = false;

View file

@ -555,61 +555,61 @@ extern "C" int vsscanf(const char* input, const char* format, va_list ap)
case ConversionSpecifier::Decimal: case ConversionSpecifier::Decimal:
if (!ReadElement<int, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<int, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Integer: case ConversionSpecifier::Integer:
if (!ReadElement<int, ReadKind::Infer> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<int, ReadKind::Infer> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Octal: case ConversionSpecifier::Octal:
if (!ReadElement<unsigned, ReadKind::Octal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<unsigned, ReadKind::Octal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Unsigned: case ConversionSpecifier::Unsigned:
if (!ReadElement<unsigned, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<unsigned, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Hex: case ConversionSpecifier::Hex:
if (!ReadElement<unsigned, ReadKind::Hex> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<unsigned, ReadKind::Hex> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Floating: case ConversionSpecifier::Floating:
if (!ReadElement<float, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<float, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::String: case ConversionSpecifier::String:
if (!ReadElement<char*, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<char*, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::UseScanList: case ConversionSpecifier::UseScanList:
if (!ReadElement<char*, ReadKind::Normal> { scanlist, invert_scanlist }(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<char*, ReadKind::Normal> { scanlist, invert_scanlist }(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Character: case ConversionSpecifier::Character:
if (!ReadElement<char, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<char, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::Pointer: case ConversionSpecifier::Pointer:
if (!ReadElement<void*, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null)) if (!ReadElement<void*, ReadKind::Normal> {}(length_modifier, input_lexer, ap_or_null))
format_lexer.consume_all(); format_lexer.consume_all();
else else if (!suppress_assignment)
++elements_matched; ++elements_matched;
break; break;
case ConversionSpecifier::OutputNumberOfBytes: { case ConversionSpecifier::OutputNumberOfBytes: {