• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Int type specifier converters for scanf -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/stdio/scanf_core/ptr_converter.h"
10 
11 #include "src/stdio/scanf_core/converter_utils.h"
12 #include "src/stdio/scanf_core/core_structs.h"
13 #include "src/stdio/scanf_core/int_converter.h"
14 #include "src/stdio/scanf_core/reader.h"
15 
16 #include <stddef.h>
17 
18 namespace LIBC_NAMESPACE {
19 namespace scanf_core {
convert_pointer(Reader * reader,const FormatSection & to_conv)20 int convert_pointer(Reader *reader, const FormatSection &to_conv) {
21   static const char nullptr_string[] = "(nullptr)";
22 
23   // Check if it's exactly the nullptr string, if so then it's a nullptr.
24   char cur_char = reader->getc();
25   size_t i = 0;
26   for (; i < sizeof(nullptr_string) && to_lower(cur_char) == nullptr_string[i];
27        ++i) {
28     cur_char = reader->getc();
29   }
30   if (i == (sizeof(nullptr_string) - 1)) {
31     *reinterpret_cast<void **>(to_conv.output_ptr) = nullptr;
32     return READ_OK;
33   } else if (i > 0) {
34     return MATCHING_FAILURE;
35   }
36 
37   reader->ungetc(cur_char);
38 
39   // Else treat it as a hex int
40   return convert_int(reader, to_conv);
41 }
42 } // namespace scanf_core
43 } // namespace LIBC_NAMESPACE
44