Coverage Report

Created: 2026-04-12 06:06

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
9.10k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
9.10k
  return &r;
13
9.10k
}
bool const* from_repr<bool, bool>(bool const&)
Line
Count
Source
11
272
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
272
  return &r;
13
272
}
char const* from_repr<char, char>(char 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 char const* from_repr<unsigned char, unsigned char>(unsigned char const&)
Line
Count
Source
11
81
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
81
  return &r;
13
81
}
signed char const* from_repr<signed char, signed char>(signed char const&)
Line
Count
Source
11
122
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
122
  return &r;
13
122
}
short const* from_repr<short, short>(short const&)
Line
Count
Source
11
170
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
170
  return &r;
13
170
}
unsigned short const* from_repr<unsigned short, unsigned short>(unsigned short const&)
Line
Count
Source
11
61
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
61
  return &r;
13
61
}
int const* from_repr<int, int>(int const&)
Line
Count
Source
11
342
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
342
  return &r;
13
342
}
unsigned int const* from_repr<unsigned int, unsigned int>(unsigned int const&)
Line
Count
Source
11
335
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
335
  return &r;
13
335
}
long const* from_repr<long, long>(long const&)
Line
Count
Source
11
778
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
778
  return &r;
13
778
}
unsigned long const* from_repr<unsigned long, unsigned long>(unsigned long const&)
Line
Count
Source
11
711
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
711
  return &r;
13
711
}
float const* from_repr<float, float>(float const&)
Line
Count
Source
11
1.63k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
1.63k
  return &r;
13
1.63k
}
double const* from_repr<double, double>(double const&)
Line
Count
Source
11
2.58k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
2.58k
  return &r;
13
2.58k
}
long double const* from_repr<long double, long double>(long double const&)
Line
Count
Source
11
1.61k
template <typename T, typename Repr> const T* from_repr(const Repr& r) {
12
1.61k
  return &r;
13
1.61k
}
14
15
2.27k
template <> const std::tm* from_repr<std::tm>(const std::time_t& t) {
16
2.27k
  return std::localtime(&t);
17
2.27k
}
18
19
template <typename T, typename Repr = T>
20
11.4k
void invoke_fmt(const uint8_t* data, size_t size) {
21
11.4k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
11.4k
  if (size <= fixed_size) return;
23
11.3k
  auto repr = assign_from_buf<Repr>(data);
24
11.3k
  const T* value = from_repr<T>(repr);
25
11.3k
  if (!value) return;
26
11.3k
  data += fixed_size;
27
11.3k
  size -= fixed_size;
28
11.3k
  data_to_string format_str(data, size);
29
11.3k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
11.3k
    auto buf = fmt::memory_buffer();
34
11.3k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
11.3k
#endif
36
11.3k
  } catch (std::exception&) {
37
8.96k
  }
38
11.3k
}
void invoke_fmt<bool, bool>(unsigned char const*, unsigned long)
Line
Count
Source
20
278
void invoke_fmt(const uint8_t* data, size_t size) {
21
278
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
278
  if (size <= fixed_size) return;
23
272
  auto repr = assign_from_buf<Repr>(data);
24
272
  const T* value = from_repr<T>(repr);
25
272
  if (!value) return;
26
272
  data += fixed_size;
27
272
  size -= fixed_size;
28
272
  data_to_string format_str(data, size);
29
272
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
272
    auto buf = fmt::memory_buffer();
34
272
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
272
#endif
36
272
  } catch (std::exception&) {
37
241
  }
38
272
}
void invoke_fmt<char, char>(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
345
  }
38
388
}
void invoke_fmt<unsigned char, unsigned char>(unsigned char const*, unsigned long)
Line
Count
Source
20
87
void invoke_fmt(const uint8_t* data, size_t size) {
21
87
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
87
  if (size <= fixed_size) return;
23
81
  auto repr = assign_from_buf<Repr>(data);
24
81
  const T* value = from_repr<T>(repr);
25
81
  if (!value) return;
26
81
  data += fixed_size;
27
81
  size -= fixed_size;
28
81
  data_to_string format_str(data, size);
29
81
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
81
    auto buf = fmt::memory_buffer();
34
81
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
81
#endif
36
81
  } catch (std::exception&) {
37
62
  }
38
81
}
void invoke_fmt<signed char, signed char>(unsigned char const*, unsigned long)
Line
Count
Source
20
128
void invoke_fmt(const uint8_t* data, size_t size) {
21
128
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
128
  if (size <= fixed_size) return;
23
122
  auto repr = assign_from_buf<Repr>(data);
24
122
  const T* value = from_repr<T>(repr);
25
122
  if (!value) return;
26
122
  data += fixed_size;
27
122
  size -= fixed_size;
28
122
  data_to_string format_str(data, size);
29
122
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
122
    auto buf = fmt::memory_buffer();
34
122
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
122
#endif
36
122
  } catch (std::exception&) {
37
96
  }
38
122
}
void invoke_fmt<short, short>(unsigned char const*, unsigned long)
Line
Count
Source
20
176
void invoke_fmt(const uint8_t* data, size_t size) {
21
176
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
176
  if (size <= fixed_size) return;
23
170
  auto repr = assign_from_buf<Repr>(data);
24
170
  const T* value = from_repr<T>(repr);
25
170
  if (!value) return;
26
170
  data += fixed_size;
27
170
  size -= fixed_size;
28
170
  data_to_string format_str(data, size);
29
170
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
170
    auto buf = fmt::memory_buffer();
34
170
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
170
#endif
36
170
  } catch (std::exception&) {
37
141
  }
38
170
}
void invoke_fmt<unsigned short, unsigned short>(unsigned char const*, unsigned long)
Line
Count
Source
20
67
void invoke_fmt(const uint8_t* data, size_t size) {
21
67
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
67
  if (size <= fixed_size) return;
23
61
  auto repr = assign_from_buf<Repr>(data);
24
61
  const T* value = from_repr<T>(repr);
25
61
  if (!value) return;
26
61
  data += fixed_size;
27
61
  size -= fixed_size;
28
61
  data_to_string format_str(data, size);
29
61
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
61
    auto buf = fmt::memory_buffer();
34
61
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
61
#endif
36
61
  } catch (std::exception&) {
37
46
  }
38
61
}
void invoke_fmt<int, int>(unsigned char const*, unsigned long)
Line
Count
Source
20
348
void invoke_fmt(const uint8_t* data, size_t size) {
21
348
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
348
  if (size <= fixed_size) return;
23
342
  auto repr = assign_from_buf<Repr>(data);
24
342
  const T* value = from_repr<T>(repr);
25
342
  if (!value) return;
26
342
  data += fixed_size;
27
342
  size -= fixed_size;
28
342
  data_to_string format_str(data, size);
29
342
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
342
    auto buf = fmt::memory_buffer();
34
342
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
342
#endif
36
342
  } catch (std::exception&) {
37
261
  }
38
342
}
void invoke_fmt<unsigned int, unsigned int>(unsigned char const*, unsigned long)
Line
Count
Source
20
341
void invoke_fmt(const uint8_t* data, size_t size) {
21
341
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
341
  if (size <= fixed_size) return;
23
335
  auto repr = assign_from_buf<Repr>(data);
24
335
  const T* value = from_repr<T>(repr);
25
335
  if (!value) return;
26
335
  data += fixed_size;
27
335
  size -= fixed_size;
28
335
  data_to_string format_str(data, size);
29
335
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
335
    auto buf = fmt::memory_buffer();
34
335
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
335
#endif
36
335
  } catch (std::exception&) {
37
224
  }
38
335
}
void invoke_fmt<long, long>(unsigned char const*, unsigned long)
Line
Count
Source
20
780
void invoke_fmt(const uint8_t* data, size_t size) {
21
780
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
780
  if (size <= fixed_size) return;
23
778
  auto repr = assign_from_buf<Repr>(data);
24
778
  const T* value = from_repr<T>(repr);
25
778
  if (!value) return;
26
778
  data += fixed_size;
27
778
  size -= fixed_size;
28
778
  data_to_string format_str(data, size);
29
778
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
778
    auto buf = fmt::memory_buffer();
34
778
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
778
#endif
36
778
  } catch (std::exception&) {
37
585
  }
38
778
}
void invoke_fmt<unsigned long, unsigned long>(unsigned char const*, unsigned long)
Line
Count
Source
20
714
void invoke_fmt(const uint8_t* data, size_t size) {
21
714
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
714
  if (size <= fixed_size) return;
23
711
  auto repr = assign_from_buf<Repr>(data);
24
711
  const T* value = from_repr<T>(repr);
25
711
  if (!value) return;
26
711
  data += fixed_size;
27
711
  size -= fixed_size;
28
711
  data_to_string format_str(data, size);
29
711
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
711
    auto buf = fmt::memory_buffer();
34
711
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
711
#endif
36
711
  } catch (std::exception&) {
37
518
  }
38
711
}
void invoke_fmt<float, float>(unsigned char const*, unsigned long)
Line
Count
Source
20
1.64k
void invoke_fmt(const uint8_t* data, size_t size) {
21
1.64k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
1.64k
  if (size <= fixed_size) return;
23
1.63k
  auto repr = assign_from_buf<Repr>(data);
24
1.63k
  const T* value = from_repr<T>(repr);
25
1.63k
  if (!value) return;
26
1.63k
  data += fixed_size;
27
1.63k
  size -= fixed_size;
28
1.63k
  data_to_string format_str(data, size);
29
1.63k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
1.63k
    auto buf = fmt::memory_buffer();
34
1.63k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
1.63k
#endif
36
1.63k
  } catch (std::exception&) {
37
1.19k
  }
38
1.63k
}
void invoke_fmt<double, double>(unsigned char const*, unsigned long)
Line
Count
Source
20
2.58k
void invoke_fmt(const uint8_t* data, size_t size) {
21
2.58k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
2.58k
  if (size <= fixed_size) return;
23
2.58k
  auto repr = assign_from_buf<Repr>(data);
24
2.58k
  const T* value = from_repr<T>(repr);
25
2.58k
  if (!value) return;
26
2.58k
  data += fixed_size;
27
2.58k
  size -= fixed_size;
28
2.58k
  data_to_string format_str(data, size);
29
2.58k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
2.58k
    auto buf = fmt::memory_buffer();
34
2.58k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
2.58k
#endif
36
2.58k
  } catch (std::exception&) {
37
1.85k
  }
38
2.58k
}
void invoke_fmt<long double, long double>(unsigned char const*, unsigned long)
Line
Count
Source
20
1.62k
void invoke_fmt(const uint8_t* data, size_t size) {
21
1.62k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
1.62k
  if (size <= fixed_size) return;
23
1.61k
  auto repr = assign_from_buf<Repr>(data);
24
1.61k
  const T* value = from_repr<T>(repr);
25
1.61k
  if (!value) return;
26
1.61k
  data += fixed_size;
27
1.61k
  size -= fixed_size;
28
1.61k
  data_to_string format_str(data, size);
29
1.61k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
1.61k
    auto buf = fmt::memory_buffer();
34
1.61k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
1.61k
#endif
36
1.61k
  } catch (std::exception&) {
37
1.27k
  }
38
1.61k
}
void invoke_fmt<tm, long>(unsigned char const*, unsigned long)
Line
Count
Source
20
2.27k
void invoke_fmt(const uint8_t* data, size_t size) {
21
2.27k
  static_assert(sizeof(Repr) <= fixed_size, "Nfixed is too small");
22
2.27k
  if (size <= fixed_size) return;
23
2.27k
  auto repr = assign_from_buf<Repr>(data);
24
2.27k
  const T* value = from_repr<T>(repr);
25
2.27k
  if (!value) return;
26
2.27k
  data += fixed_size;
27
2.27k
  size -= fixed_size;
28
2.27k
  data_to_string format_str(data, size);
29
2.27k
  try {
30
#if FMT_FUZZ_FORMAT_TO_STRING
31
    std::string message = fmt::format(format_str.get(), *value);
32
#else
33
2.27k
    auto buf = fmt::memory_buffer();
34
2.27k
    fmt::format_to(std::back_inserter(buf), format_str.get(), *value);
35
2.27k
#endif
36
2.27k
  } catch (std::exception&) {
37
2.12k
  }
38
2.27k
}
39
40
11.4k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
41
11.4k
  if (size <= 3) return 0;
42
43
11.4k
  const auto first = data[0];
44
11.4k
  data++;
45
11.4k
  size--;
46
47
11.4k
  switch (first) {
48
278
  case 0:
49
278
    invoke_fmt<bool>(data, size);
50
278
    break;
51
394
  case 1:
52
394
    invoke_fmt<char>(data, size);
53
394
    break;
54
87
  case 2:
55
87
    invoke_fmt<unsigned char>(data, size);
56
87
    break;
57
128
  case 3:
58
128
    invoke_fmt<signed char>(data, size);
59
128
    break;
60
176
  case 4:
61
176
    invoke_fmt<short>(data, size);
62
176
    break;
63
67
  case 5:
64
67
    invoke_fmt<unsigned short>(data, size);
65
67
    break;
66
348
  case 6:
67
348
    invoke_fmt<int>(data, size);
68
348
    break;
69
341
  case 7:
70
341
    invoke_fmt<unsigned int>(data, size);
71
341
    break;
72
780
  case 8:
73
780
    invoke_fmt<long>(data, size);
74
780
    break;
75
714
  case 9:
76
714
    invoke_fmt<unsigned long>(data, size);
77
714
    break;
78
1.64k
  case 10:
79
1.64k
    invoke_fmt<float>(data, size);
80
1.64k
    break;
81
2.58k
  case 11:
82
2.58k
    invoke_fmt<double>(data, size);
83
2.58k
    break;
84
1.62k
  case 12:
85
1.62k
    invoke_fmt<long double>(data, size);
86
1.62k
    break;
87
2.27k
  case 13:
88
2.27k
    invoke_fmt<std::tm, std::time_t>(data, size);
89
2.27k
    break;
90
11.4k
  }
91
11.4k
  return 0;
92
11.4k
}