Sfoglia il codice sorgente

LibC: Teach `vsscanf()` to consume the width specifier

Previously, `vsscanf()` would crash whenever it encountered a width
specification. Now, it consumes the width specification but does not
yet do anything with it.
Jelle Raaijmakers 4 anni fa
parent
commit
5e5f0245b6
2 ha cambiato i file con 9 aggiunte e 0 eliminazioni
  1. 8 0
      Userland/Libraries/LibC/scanf.cpp
  2. 1 0
      Userland/Tests/LibC/scanf.cpp

+ 8 - 0
Userland/Libraries/LibC/scanf.cpp

@@ -418,6 +418,14 @@ extern "C" int vsscanf(const char* input, const char* format, va_list ap)
 
         format_lexer.ignore(); // '%'
 
+        // Parse width specification
+        [[maybe_unused]] int width_specifier = 0;
+        if (format_lexer.next_is(isdigit)) {
+            auto width_digits = format_lexer.consume_while([](char c) { return isdigit(c); });
+            width_specifier = width_digits.to_int().value();
+            // FIXME: Actually use width specifier
+        }
+
         bool invert_scanlist = false;
         StringView scanlist;
         LengthModifier length_modifier { None };

+ 1 - 0
Userland/Tests/LibC/scanf.cpp

@@ -170,6 +170,7 @@ const TestSuite test_suites[] {
     { "%d", "", 0, 0, {}, {} },
     { "%x", "0x519", 1, 1, { unsignedarg0 }, { to_value_t(0x519) } },
     { "%x", "0x51g", 1, 1, { unsignedarg0 }, { to_value_t(0x51u) } },
+    { "%06x", "0xabcdef", 1, 1, { unsignedarg0 }, { to_value_t(0xabcdefu) } },
     { "\"%%%d#", "\"%42#", 1, 1, { intarg0 }, { to_value_t(42) } },
     { "  %d", "42", 1, 1, { intarg0 }, { to_value_t(42) } },
     { "%d", "  42", 1, 1, { intarg0 }, { to_value_t(42) } },