Coverage Report

Created: 2026-01-09 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fmt/test/fuzzing/one-arg.cc
Line
Count
Source
1
// Copyright (c) 2019, Paul Dreik
2
// For the license information refer to format.h.
3
4
#include <fmt/chrono.h>
5
6
#include <cstdint>
7
#include <exception>
8
9
#include "fuzzer-common.h"
10
11
10.1k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
10.1k
  return &r;
13
10.1k
}
bool const* from_repr<bool, bool>(bool const&)
Line
Count
Source
11
286
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
286
  return &r;
13
286
}
char const* from_repr<char, char>(char const&)
Line
Count
Source
11
403
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
403
  return &r;
13
403
}
unsigned char const* from_repr<unsigned char, unsigned char>(unsigned char const&)
Line
Count
Source
11
93
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
93
  return &r;
13
93
}
signed char const* from_repr<signed char, signed char>(signed char const&)
Line
Count
Source
11
102
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
102
  return &r;
13
102
}
short const* from_repr<short, short>(short const&)
Line
Count
Source
11
164
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
164
  return &r;
13
164
}
unsigned short const* from_repr<unsigned short, unsigned short>(unsigned short const&)
Line
Count
Source
11
63
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
63
  return &r;
13
63
}
int const* from_repr<int, int>(int const&)
Line
Count
Source
11
388
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
388
  return &r;
13
388
}
unsigned int const* from_repr<unsigned int, unsigned int>(unsigned int const&)
Line
Count
Source
11
344
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
344
  return &r;
13
344
}
long const* from_repr<long, long>(long const&)
Line
Count
Source
11
928
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
928
  return &r;
13
928
}
unsigned long const* from_repr<unsigned long, unsigned long>(unsigned long const&)
Line
Count
Source
11
720
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
720
  return &r;
13
720
}
float const* from_repr<float, float>(float const&)
Line
Count
Source
11
1.97k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
1.97k
  return &r;
13
1.97k
}
double const* from_repr<double, double>(double const&)
Line
Count
Source
11
2.91k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
2.91k
  return &r;
13
2.91k
}
long double const* from_repr<long double, long double>(long double const&)
Line
Count
Source
11
1.76k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
1.76k
  return &r;
13
1.76k
}
14
15
2.45k
template <> const std::tm* from_repr<std::tm>(const std::time_t& t) {
16
2.45k
  return std::localtime(&t);
17
2.45k
}
18
19
template <typename T, typename Repr = T>
20
12.6k
void invoke_fmt(const uint8_t* data, size_t size) {
21
12.6k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
12.6k
  if (size <= fixed_size) return;
23
12.6k
  auto repr = assign_from_buf<Repr>(data);
24
12.6k
  const T* value = from_repr<T>(repr);
25
12.6k
  if (!value) return;
26
12.5k
  data += fixed_size;
27
12.5k
  size -= fixed_size;
28
12.5k
  data_to_string format_str(data, size);
29
12.5k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
12.5k
    auto buf = fmt::memory_buffer();
34
12.5k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
12.5k
#endif
36
12.5k
  } catch (std::exception&) {
37
9.96k
  }
38
12.5k
}
void invoke_fmt<bool, bool>(unsigned char const*, unsigned long)
Line
Count
Source
20
292
void invoke_fmt(const uint8_t* data, size_t size) {
21
292
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
292
  if (size <= fixed_size) return;
23
286
  auto repr = assign_from_buf<Repr>(data);
24
286
  const T* value = from_repr<T>(repr);
25
286
  if (!value) return;
26
286
  data += fixed_size;
27
286
  size -= fixed_size;
28
286
  data_to_string format_str(data, size);
29
286
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
286
    auto buf = fmt::memory_buffer();
34
286
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
286
#endif
36
286
  } catch (std::exception&) {
37
248
  }
38
286
}
void invoke_fmt<char, char>(unsigned char const*, unsigned long)
Line
Count
Source
20
409
void invoke_fmt(const uint8_t* data, size_t size) {
21
409
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
409
  if (size <= fixed_size) return;
23
403
  auto repr = assign_from_buf<Repr>(data);
24
403
  const T* value = from_repr<T>(repr);
25
403
  if (!value) return;
26
403
  data += fixed_size;
27
403
  size -= fixed_size;
28
403
  data_to_string format_str(data, size);
29
403
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
403
    auto buf = fmt::memory_buffer();
34
403
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
403
#endif
36
403
  } catch (std::exception&) {
37
360
  }
38
403
}
void invoke_fmt<unsigned char, unsigned char>(unsigned char const*, unsigned long)
Line
Count
Source
20
99
void invoke_fmt(const uint8_t* data, size_t size) {
21
99
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
99
  if (size <= fixed_size) return;
23
93
  auto repr = assign_from_buf<Repr>(data);
24
93
  const T* value = from_repr<T>(repr);
25
93
  if (!value) return;
26
93
  data += fixed_size;
27
93
  size -= fixed_size;
28
93
  data_to_string format_str(data, size);
29
93
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
93
    auto buf = fmt::memory_buffer();
34
93
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
93
#endif
36
93
  } catch (std::exception&) {
37
63
  }
38
93
}
void invoke_fmt<signed char, signed char>(unsigned char const*, unsigned long)
Line
Count
Source
20
108
void invoke_fmt(const uint8_t* data, size_t size) {
21
108
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
108
  if (size <= fixed_size) return;
23
102
  auto repr = assign_from_buf<Repr>(data);
24
102
  const T* value = from_repr<T>(repr);
25
102
  if (!value) return;
26
102
  data += fixed_size;
27
102
  size -= fixed_size;
28
102
  data_to_string format_str(data, size);
29
102
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
102
    auto buf = fmt::memory_buffer();
34
102
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
102
#endif
36
102
  } catch (std::exception&) {
37
76
  }
38
102
}
void invoke_fmt<short, short>(unsigned char const*, unsigned long)
Line
Count
Source
20
170
void invoke_fmt(const uint8_t* data, size_t size) {
21
170
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
170
  if (size <= fixed_size) return;
23
164
  auto repr = assign_from_buf<Repr>(data);
24
164
  const T* value = from_repr<T>(repr);
25
164
  if (!value) return;
26
164
  data += fixed_size;
27
164
  size -= fixed_size;
28
164
  data_to_string format_str(data, size);
29
164
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
164
    auto buf = fmt::memory_buffer();
34
164
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
164
#endif
36
164
  } catch (std::exception&) {
37
143
  }
38
164
}
void invoke_fmt<unsigned short, unsigned short>(unsigned char const*, unsigned long)
Line
Count
Source
20
69
void invoke_fmt(const uint8_t* data, size_t size) {
21
69
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
69
  if (size <= fixed_size) return;
23
63
  auto repr = assign_from_buf<Repr>(data);
24
63
  const T* value = from_repr<T>(repr);
25
63
  if (!value) return;
26
63
  data += fixed_size;
27
63
  size -= fixed_size;
28
63
  data_to_string format_str(data, size);
29
63
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
63
    auto buf = fmt::memory_buffer();
34
63
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
63
#endif
36
63
  } catch (std::exception&) {
37
50
  }
38
63
}
void invoke_fmt<int, int>(unsigned char const*, unsigned long)
Line
Count
Source
20
394
void invoke_fmt(const uint8_t* data, size_t size) {
21
394
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
394
  if (size <= fixed_size) return;
23
388
  auto repr = assign_from_buf<Repr>(data);
24
388
  const T* value = from_repr<T>(repr);
25
388
  if (!value) return;
26
388
  data += fixed_size;
27
388
  size -= fixed_size;
28
388
  data_to_string format_str(data, size);
29
388
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
388
    auto buf = fmt::memory_buffer();
34
388
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
388
#endif
36
388
  } catch (std::exception&) {
37
303
  }
38
388
}
void invoke_fmt<unsigned int, unsigned int>(unsigned char const*, unsigned long)
Line
Count
Source
20
350
void invoke_fmt(const uint8_t* data, size_t size) {
21
350
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
350
  if (size <= fixed_size) return;
23
344
  auto repr = assign_from_buf<Repr>(data);
24
344
  const T* value = from_repr<T>(repr);
25
344
  if (!value) return;
26
344
  data += fixed_size;
27
344
  size -= fixed_size;
28
344
  data_to_string format_str(data, size);
29
344
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
344
    auto buf = fmt::memory_buffer();
34
344
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
344
#endif
36
344
  } catch (std::exception&) {
37
225
  }
38
344
}
void invoke_fmt<long, long>(unsigned char const*, unsigned long)
Line
Count
Source
20
931
void invoke_fmt(const uint8_t* data, size_t size) {
21
931
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
931
  if (size <= fixed_size) return;
23
928
  auto repr = assign_from_buf<Repr>(data);
24
928
  const T* value = from_repr<T>(repr);
25
928
  if (!value) return;
26
928
  data += fixed_size;
27
928
  size -= fixed_size;
28
928
  data_to_string format_str(data, size);
29
928
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
928
    auto buf = fmt::memory_buffer();
34
928
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
928
#endif
36
928
  } catch (std::exception&) {
37
717
  }
38
928
}
void invoke_fmt<unsigned long, unsigned long>(unsigned char const*, unsigned long)
Line
Count
Source
20
722
void invoke_fmt(const uint8_t* data, size_t size) {
21
722
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
722
  if (size <= fixed_size) return;
23
720
  auto repr = assign_from_buf<Repr>(data);
24
720
  const T* value = from_repr<T>(repr);
25
720
  if (!value) return;
26
720
  data += fixed_size;
27
720
  size -= fixed_size;
28
720
  data_to_string format_str(data, size);
29
720
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
720
    auto buf = fmt::memory_buffer();
34
720
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
720
#endif
36
720
  } catch (std::exception&) {
37
521
  }
38
720
}
void invoke_fmt<float, float>(unsigned char const*, unsigned long)
Line
Count
Source
20
1.98k
void invoke_fmt(const uint8_t* data, size_t size) {
21
1.98k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
1.98k
  if (size <= fixed_size) return;
23
1.97k
  auto repr = assign_from_buf<Repr>(data);
24
1.97k
  const T* value = from_repr<T>(repr);
25
1.97k
  if (!value) return;
26
1.97k
  data += fixed_size;
27
1.97k
  size -= fixed_size;
28
1.97k
  data_to_string format_str(data, size);
29
1.97k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
1.97k
    auto buf = fmt::memory_buffer();
34
1.97k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
1.97k
#endif
36
1.97k
  } catch (std::exception&) {
37
1.49k
  }
38
1.97k
}
void invoke_fmt<double, double>(unsigned char const*, unsigned long)
Line
Count
Source
20
2.91k
void invoke_fmt(const uint8_t* data, size_t size) {
21
2.91k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
2.91k
  if (size <= fixed_size) return;
23
2.91k
  auto repr = assign_from_buf<Repr>(data);
24
2.91k
  const T* value = from_repr<T>(repr);
25
2.91k
  if (!value) return;
26
2.91k
  data += fixed_size;
27
2.91k
  size -= fixed_size;
28
2.91k
  data_to_string format_str(data, size);
29
2.91k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
2.91k
    auto buf = fmt::memory_buffer();
34
2.91k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
2.91k
#endif
36
2.91k
  } catch (std::exception&) {
37
2.09k
  }
38
2.91k
}
void invoke_fmt<long double, long double>(unsigned char const*, unsigned long)
Line
Count
Source
20
1.76k
void invoke_fmt(const uint8_t* data, size_t size) {
21
1.76k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
1.76k
  if (size <= fixed_size) return;
23
1.76k
  auto repr = assign_from_buf<Repr>(data);
24
1.76k
  const T* value = from_repr<T>(repr);
25
1.76k
  if (!value) return;
26
1.76k
  data += fixed_size;
27
1.76k
  size -= fixed_size;
28
1.76k
  data_to_string format_str(data, size);
29
1.76k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
1.76k
    auto buf = fmt::memory_buffer();
34
1.76k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
1.76k
#endif
36
1.76k
  } catch (std::exception&) {
37
1.35k
  }
38
1.76k
}
void invoke_fmt<tm, long>(unsigned char const*, unsigned long)
Line
Count
Source
20
2.46k
void invoke_fmt(const uint8_t* data, size_t size) {
21
2.46k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
2.46k
  if (size <= fixed_size) return;
23
2.45k
  auto repr = assign_from_buf<Repr>(data);
24
2.45k
  const T* value = from_repr<T>(repr);
25
2.45k
  if (!value) return;
26
2.45k
  data += fixed_size;
27
2.45k
  size -= fixed_size;
28
2.45k
  data_to_string format_str(data, size);
29
2.45k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
2.45k
    auto buf = fmt::memory_buffer();
34
2.45k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
2.45k
#endif
36
2.45k
  } catch (std::exception&) {
37
2.31k
  }
38
2.45k
}
39
40
12.6k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
41
12.6k
  if (size <= 3) return 0;
42
43
12.6k
  const auto first = data[0];
44
12.6k
  data++;
45
12.6k
  size--;
46
47
12.6k
  switch (first) {
48
292
  case 0:
49
292
    invoke_fmt<bool>(data, size);
50
292
    break;
51
409
  case 1:
52
409
    invoke_fmt<char>(data, size);
53
409
    break;
54
99
  case 2:
55
99
    invoke_fmt<unsigned char>(data, size);
56
99
    break;
57
108
  case 3:
58
108
    invoke_fmt<signed char>(data, size);
59
108
    break;
60
170
  case 4:
61
170
    invoke_fmt<short>(data, size);
62
170
    break;
63
69
  case 5:
64
69
    invoke_fmt<unsigned short>(data, size);
65
69
    break;
66
394
  case 6:
67
394
    invoke_fmt<int>(data, size);
68
394
    break;
69
350
  case 7:
70
350
    invoke_fmt<unsigned int>(data, size);
71
350
    break;
72
931
  case 8:
73
931
    invoke_fmt<long>(data, size);
74
931
    break;
75
722
  case 9:
76
722
    invoke_fmt<unsigned long>(data, size);
77
722
    break;
78
1.98k
  case 10:
79
1.98k
    invoke_fmt<float>(data, size);
80
1.98k
    break;
81
2.91k
  case 11:
82
2.91k
    invoke_fmt<double>(data, size);
83
2.91k
    break;
84
1.76k
  case 12:
85
1.76k
    invoke_fmt<long double>(data, size);
86
1.76k
    break;
87
2.46k
  case 13:
88
2.46k
    invoke_fmt<std::tm, std::time_t>(data, size);
89
2.46k
    break;
90
12.6k
  }
91
12.6k
  return 0;
92
12.6k
}