Coverage Report

Created: 2026-10-22 06:56

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
7
{
24
7
  dynbuf buffer;
25
7
  curlx_dyn_init(&buffer, limit);
26
7
  va_list args;
27
7
  va_start(args, format);
28
7
  volatile int result = curlx_dyn_vprintf(&buffer, format, args);
29
7
  va_end(args);
30
7
  (void)result;
31
7
  curlx_dyn_free(&buffer);
32
7
}
33
34
}  // namespace
35
36
void ExerciseDynamicFormattingCoverage()
37
1
{
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
1
  ExerciseFormat(8, "%s", "1234567");
41
1
  ExerciseFormat(8, "%s", "12345678");
42
1
  ExerciseFormat(8, "%08d", 1);
43
1
  ExerciseFormat(8, "%c", 'x');
44
1
  ExerciseFormat(8, "%s", "");
45
46
1
  char text[601];
47
1
  std::memset(text, 'x', sizeof(text) - 1);
48
1
  text[sizeof(text) - 1] = '\0';
49
  // Cross the staging buffer boundary both with room and at a small limit.
50
1
  ExerciseFormat(1024, "%s", text);
51
1
  ExerciseFormat(512, "%s", text);
52
1
}
53
54
}  // namespace full_coverage