Coverage Report

Created: 2026-12-04 06:31

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
#include <iterator>
9
10
#include "fuzzer-common.h"
11
12
10.2k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
10.2k
  return &r;
14
10.2k
}
bool const* from_repr<bool, bool>(bool const&)
Line
Count
Source
12
288
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
288
  return &r;
14
288
}
char const* from_repr<char, char>(char const&)
Line
Count
Source
12
324
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
324
  return &r;
14
324
}
unsigned char const* from_repr<unsigned char, unsigned char>(unsigned char const&)
Line
Count
Source
12
82
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
82
  return &r;
14
82
}
signed char const* from_repr<signed char, signed char>(signed char const&)
Line
Count
Source
12
119
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
119
  return &r;
14
119
}
short const* from_repr<short, short>(short const&)
Line
Count
Source
12
180
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
180
  return &r;
14
180
}
unsigned short const* from_repr<unsigned short, unsigned short>(unsigned short const&)
Line
Count
Source
12
88
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
88
  return &r;
14
88
}
int const* from_repr<int, int>(int const&)
Line
Count
Source
12
481
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
481
  return &r;
14
481
}
unsigned int const* from_repr<unsigned int, unsigned int>(unsigned int const&)
Line
Count
Source
12
390
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
390
  return &r;
14
390
}
long const* from_repr<long, long>(long const&)
Line
Count
Source
12
794
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
794
  return &r;
14
794
}
unsigned long const* from_repr<unsigned long, unsigned long>(unsigned long const&)
Line
Count
Source
12
885
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
885
  return &r;
14
885
}
float const* from_repr<float, float>(float const&)
Line
Count
Source
12
1.93k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
1.93k
  return &r;
14
1.93k
}
double const* from_repr<double, double>(double const&)
Line
Count
Source
12
2.88k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
2.88k
  return &r;
14
2.88k
}
long double const* from_repr<long double, long double>(long double const&)
Line
Count
Source
12
1.83k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
13
1.83k
  return &r;
14
1.83k
}
15
16
2.23k
template <> const std::tm* from_repr<std::tm>(const std::time_t& t) {
17
2.23k
  return std::localtime(&t);
18
2.23k
}
19
20
template <typename T, typename Repr = T>
21
12.5k
void invoke_fmt(const uint8_t* data, size_t size) {
22
12.5k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
12.5k
  if (size <= fixed_size) return;
24
12.5k
  auto repr = assign_from_buf<Repr>(data);
25
12.5k
  const T* value = from_repr<T>(repr);
26
12.5k
  if (!value) return;
27
12.5k
  data += fixed_size;
28
12.5k
  size -= fixed_size;
29
12.5k
  data_to_string format_str(data, size);
30
12.5k
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
12.5k
    auto buf = fmt::memory_buffer();
35
12.5k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
12.5k
#endif
37
12.5k
  } catch (std::exception&) {
38
10.6k
  }
39
12.5k
}
void invoke_fmt<bool, bool>(unsigned char const*, unsigned long)
Line
Count
Source
21
294
void invoke_fmt(const uint8_t* data, size_t size) {
22
294
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
294
  if (size <= fixed_size) return;
24
288
  auto repr = assign_from_buf<Repr>(data);
25
288
  const T* value = from_repr<T>(repr);
26
288
  if (!value) return;
27
288
  data += fixed_size;
28
288
  size -= fixed_size;
29
288
  data_to_string format_str(data, size);
30
288
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
288
    auto buf = fmt::memory_buffer();
35
288
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
288
#endif
37
288
  } catch (std::exception&) {
38
248
  }
39
288
}
void invoke_fmt<char, char>(unsigned char const*, unsigned long)
Line
Count
Source
21
330
void invoke_fmt(const uint8_t* data, size_t size) {
22
330
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
330
  if (size <= fixed_size) return;
24
324
  auto repr = assign_from_buf<Repr>(data);
25
324
  const T* value = from_repr<T>(repr);
26
324
  if (!value) return;
27
324
  data += fixed_size;
28
324
  size -= fixed_size;
29
324
  data_to_string format_str(data, size);
30
324
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
324
    auto buf = fmt::memory_buffer();
35
324
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
324
#endif
37
324
  } catch (std::exception&) {
38
305
  }
39
324
}
void invoke_fmt<unsigned char, unsigned char>(unsigned char const*, unsigned long)
Line
Count
Source
21
88
void invoke_fmt(const uint8_t* data, size_t size) {
22
88
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
88
  if (size <= fixed_size) return;
24
82
  auto repr = assign_from_buf<Repr>(data);
25
82
  const T* value = from_repr<T>(repr);
26
82
  if (!value) return;
27
82
  data += fixed_size;
28
82
  size -= fixed_size;
29
82
  data_to_string format_str(data, size);
30
82
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
82
    auto buf = fmt::memory_buffer();
35
82
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
82
#endif
37
82
  } catch (std::exception&) {
38
65
  }
39
82
}
void invoke_fmt<signed char, signed char>(unsigned char const*, unsigned long)
Line
Count
Source
21
125
void invoke_fmt(const uint8_t* data, size_t size) {
22
125
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
125
  if (size <= fixed_size) return;
24
119
  auto repr = assign_from_buf<Repr>(data);
25
119
  const T* value = from_repr<T>(repr);
26
119
  if (!value) return;
27
119
  data += fixed_size;
28
119
  size -= fixed_size;
29
119
  data_to_string format_str(data, size);
30
119
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
119
    auto buf = fmt::memory_buffer();
35
119
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
119
#endif
37
119
  } catch (std::exception&) {
38
97
  }
39
119
}
void invoke_fmt<short, short>(unsigned char const*, unsigned long)
Line
Count
Source
21
186
void invoke_fmt(const uint8_t* data, size_t size) {
22
186
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
186
  if (size <= fixed_size) return;
24
180
  auto repr = assign_from_buf<Repr>(data);
25
180
  const T* value = from_repr<T>(repr);
26
180
  if (!value) return;
27
180
  data += fixed_size;
28
180
  size -= fixed_size;
29
180
  data_to_string format_str(data, size);
30
180
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
180
    auto buf = fmt::memory_buffer();
35
180
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
180
#endif
37
180
  } catch (std::exception&) {
38
154
  }
39
180
}
void invoke_fmt<unsigned short, unsigned short>(unsigned char const*, unsigned long)
Line
Count
Source
21
94
void invoke_fmt(const uint8_t* data, size_t size) {
22
94
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
94
  if (size <= fixed_size) return;
24
88
  auto repr = assign_from_buf<Repr>(data);
25
88
  const T* value = from_repr<T>(repr);
26
88
  if (!value) return;
27
88
  data += fixed_size;
28
88
  size -= fixed_size;
29
88
  data_to_string format_str(data, size);
30
88
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
88
    auto buf = fmt::memory_buffer();
35
88
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
88
#endif
37
88
  } catch (std::exception&) {
38
68
  }
39
88
}
void invoke_fmt<int, int>(unsigned char const*, unsigned long)
Line
Count
Source
21
487
void invoke_fmt(const uint8_t* data, size_t size) {
22
487
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
487
  if (size <= fixed_size) return;
24
481
  auto repr = assign_from_buf<Repr>(data);
25
481
  const T* value = from_repr<T>(repr);
26
481
  if (!value) return;
27
481
  data += fixed_size;
28
481
  size -= fixed_size;
29
481
  data_to_string format_str(data, size);
30
481
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
481
    auto buf = fmt::memory_buffer();
35
481
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
481
#endif
37
481
  } catch (std::exception&) {
38
402
  }
39
481
}
void invoke_fmt<unsigned int, unsigned int>(unsigned char const*, unsigned long)
Line
Count
Source
21
396
void invoke_fmt(const uint8_t* data, size_t size) {
22
396
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
396
  if (size <= fixed_size) return;
24
390
  auto repr = assign_from_buf<Repr>(data);
25
390
  const T* value = from_repr<T>(repr);
26
390
  if (!value) return;
27
390
  data += fixed_size;
28
390
  size -= fixed_size;
29
390
  data_to_string format_str(data, size);
30
390
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
390
    auto buf = fmt::memory_buffer();
35
390
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
390
#endif
37
390
  } catch (std::exception&) {
38
285
  }
39
390
}
void invoke_fmt<long, long>(unsigned char const*, unsigned long)
Line
Count
Source
21
797
void invoke_fmt(const uint8_t* data, size_t size) {
22
797
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
797
  if (size <= fixed_size) return;
24
794
  auto repr = assign_from_buf<Repr>(data);
25
794
  const T* value = from_repr<T>(repr);
26
794
  if (!value) return;
27
794
  data += fixed_size;
28
794
  size -= fixed_size;
29
794
  data_to_string format_str(data, size);
30
794
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
794
    auto buf = fmt::memory_buffer();
35
794
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
794
#endif
37
794
  } catch (std::exception&) {
38
621
  }
39
794
}
void invoke_fmt<unsigned long, unsigned long>(unsigned char const*, unsigned long)
Line
Count
Source
21
887
void invoke_fmt(const uint8_t* data, size_t size) {
22
887
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
887
  if (size <= fixed_size) return;
24
885
  auto repr = assign_from_buf<Repr>(data);
25
885
  const T* value = from_repr<T>(repr);
26
885
  if (!value) return;
27
885
  data += fixed_size;
28
885
  size -= fixed_size;
29
885
  data_to_string format_str(data, size);
30
885
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
885
    auto buf = fmt::memory_buffer();
35
885
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
885
#endif
37
885
  } catch (std::exception&) {
38
691
  }
39
885
}
void invoke_fmt<float, float>(unsigned char const*, unsigned long)
Line
Count
Source
21
1.94k
void invoke_fmt(const uint8_t* data, size_t size) {
22
1.94k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
1.94k
  if (size <= fixed_size) return;
24
1.93k
  auto repr = assign_from_buf<Repr>(data);
25
1.93k
  const T* value = from_repr<T>(repr);
26
1.93k
  if (!value) return;
27
1.93k
  data += fixed_size;
28
1.93k
  size -= fixed_size;
29
1.93k
  data_to_string format_str(data, size);
30
1.93k
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
1.93k
    auto buf = fmt::memory_buffer();
35
1.93k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
1.93k
#endif
37
1.93k
  } catch (std::exception&) {
38
1.68k
  }
39
1.93k
}
void invoke_fmt<double, double>(unsigned char const*, unsigned long)
Line
Count
Source
21
2.88k
void invoke_fmt(const uint8_t* data, size_t size) {
22
2.88k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
2.88k
  if (size <= fixed_size) return;
24
2.88k
  auto repr = assign_from_buf<Repr>(data);
25
2.88k
  const T* value = from_repr<T>(repr);
26
2.88k
  if (!value) return;
27
2.88k
  data += fixed_size;
28
2.88k
  size -= fixed_size;
29
2.88k
  data_to_string format_str(data, size);
30
2.88k
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
2.88k
    auto buf = fmt::memory_buffer();
35
2.88k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
2.88k
#endif
37
2.88k
  } catch (std::exception&) {
38
2.46k
  }
39
2.88k
}
void invoke_fmt<long double, long double>(unsigned char const*, unsigned long)
Line
Count
Source
21
1.83k
void invoke_fmt(const uint8_t* data, size_t size) {
22
1.83k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
1.83k
  if (size <= fixed_size) return;
24
1.83k
  auto repr = assign_from_buf<Repr>(data);
25
1.83k
  const T* value = from_repr<T>(repr);
26
1.83k
  if (!value) return;
27
1.83k
  data += fixed_size;
28
1.83k
  size -= fixed_size;
29
1.83k
  data_to_string format_str(data, size);
30
1.83k
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
1.83k
    auto buf = fmt::memory_buffer();
35
1.83k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
1.83k
#endif
37
1.83k
  } catch (std::exception&) {
38
1.45k
  }
39
1.83k
}
void invoke_fmt<tm, long>(unsigned char const*, unsigned long)
Line
Count
Source
21
2.24k
void invoke_fmt(const uint8_t* data, size_t size) {
22
2.24k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
23
2.24k
  if (size <= fixed_size) return;
24
2.23k
  auto repr = assign_from_buf<Repr>(data);
25
2.23k
  const T* value = from_repr<T>(repr);
26
2.23k
  if (!value) return;
27
2.23k
  data += fixed_size;
28
2.23k
  size -= fixed_size;
29
2.23k
  data_to_string format_str(data, size);
30
2.23k
  try {
31
#if FMT_FUZZ_FORMAT_TO_STRING
32
    std::string message = fmt::format(format_str.get(), *value);
33
#else
34
2.23k
    auto buf = fmt::memory_buffer();
35
2.23k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
36
2.23k
#endif
37
2.23k
  } catch (std::exception&) {
38
2.10k
  }
39
2.23k
}
40
41
12.5k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
42
12.5k
  if (size <= 3) return 0;
43
44
12.5k
  const auto first = data[0];
45
12.5k
  data++;
46
12.5k
  size--;
47
48
12.5k
  switch (first) {
49
294
  case 0:
50
294
    invoke_fmt<bool>(data, size);
51
294
    break;
52
330
  case 1:
53
330
    invoke_fmt<char>(data, size);
54
330
    break;
55
88
  case 2:
56
88
    invoke_fmt<unsigned char>(data, size);
57
88
    break;
58
125
  case 3:
59
125
    invoke_fmt<signed char>(data, size);
60
125
    break;
61
186
  case 4:
62
186
    invoke_fmt<short>(data, size);
63
186
    break;
64
94
  case 5:
65
94
    invoke_fmt<unsigned short>(data, size);
66
94
    break;
67
487
  case 6:
68
487
    invoke_fmt<int>(data, size);
69
487
    break;
70
396
  case 7:
71
396
    invoke_fmt<unsigned int>(data, size);
72
396
    break;
73
797
  case 8:
74
797
    invoke_fmt<long>(data, size);
75
797
    break;
76
887
  case 9:
77
887
    invoke_fmt<unsigned long>(data, size);
78
887
    break;
79
1.94k
  case 10:
80
1.94k
    invoke_fmt<float>(data, size);
81
1.94k
    break;
82
2.88k
  case 11:
83
2.88k
    invoke_fmt<double>(data, size);
84
2.88k
    break;
85
1.83k
  case 12:
86
1.83k
    invoke_fmt<long double>(data, size);
87
1.83k
    break;
88
2.24k
  case 13:
89
2.24k
    invoke_fmt<std::tm, std::time_t>(data, size);
90
2.24k
    break;
91
12.5k
  }
92
12.5k
  return 0;
93
12.5k
}