Coverage Report

Created: 2026-10-15 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl_fuzzer/full_coverage/dynamic_formatting.cc
Line
Count
Source
1
/*
2
 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3
 *
4
 * SPDX-License-Identifier: curl
5
 */
6
7
#include "full_coverage/dynamic_formatting.h"
8
9
#include <cstdarg>
10
#include <cstring>
11
12
// Use curl's real private layout, including its debug-build fields.
13
extern "C" {
14
#include "curl_setup.h"
15
#include "curlx/dynbuf.h"
16
}
17
18
namespace full_coverage {
19
namespace {
20
21
/** Call the va_list formatter with an independently bounded destination. */
22
void ExerciseFormat(size_t limit, const char *format, ...)
23
0
{
24
0
  dynbuf buffer;
25
0
  curlx_dyn_init(&buffer, limit);
26
0
  va_list args;
27
0
  va_start(args, format);
28
0
  volatile int result = curlx_dyn_vprintf(&buffer, format, args);
29
0
  va_end(args);
30
0
  (void)result;
31
0
  curlx_dyn_free(&buffer);
32
0
}
33
34
}  // namespace
35
36
void ExerciseDynamicFormattingCoverage()
37
0
{
38
  // Exact fit and the first byte above the limit cover the staged formatter's
39
  // normal size-limit handling without relying on failed allocations.
40
0
  ExerciseFormat(8, "%s", "1234567");
41
0
  ExerciseFormat(8, "%s", "12345678");
42
0
  ExerciseFormat(8, "%08d", 1);
43
0
  ExerciseFormat(8, "%c", 'x');
44
0
  ExerciseFormat(8, "%s", "");
45
46
0
  char text[601];
47
0
  std::memset(text, 'x', sizeof(text) - 1);
48
0
  text[sizeof(text) - 1] = '\0';
49
  // Cross the staging buffer boundary both with room and at a small limit.
50
0
  ExerciseFormat(1024, "%s", text);
51
0
  ExerciseFormat(512, "%s", text);
52
0
}
53
54
}  // namespace full_coverage