Coverage Report

Created: 2026-07-14 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/yaml_write_handler.h
Line
Count
Source
1
// Copyright 2020 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef YAML_WRITE_HANDLER_H_
16
#define YAML_WRITE_HANDLER_H_
17
18
typedef struct yaml_output_buffer {
19
  unsigned char *buf;
20
  size_t size;
21
  size_t capacity;
22
} yaml_output_buffer_t;
23
24
957k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
957k
  size_t newsize;
26
957k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
957k
  if (out->size + size >= out->capacity) {
30
28.5k
    newsize = out->capacity << 1;
31
28.5k
    if (newsize < out->size + size) {
32
6.79k
      newsize = out->size + size;
33
6.79k
    }
34
28.5k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.5k
    out->capacity = newsize;
36
28.5k
  }
37
957k
  if (!out->buf) {
38
20.9k
    out->size = 0;
39
20.9k
    return 0;
40
20.9k
  }
41
42
936k
  memcpy(out->buf + out->size, buffer, size);
43
936k
  out->size += size;
44
936k
  return 1;
45
957k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
217k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
217k
  size_t newsize;
26
217k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
217k
  if (out->size + size >= out->capacity) {
30
6.16k
    newsize = out->capacity << 1;
31
6.16k
    if (newsize < out->size + size) {
32
1.26k
      newsize = out->size + size;
33
1.26k
    }
34
6.16k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.16k
    out->capacity = newsize;
36
6.16k
  }
37
217k
  if (!out->buf) {
38
4.86k
    out->size = 0;
39
4.86k
    return 0;
40
4.86k
  }
41
42
212k
  memcpy(out->buf + out->size, buffer, size);
43
212k
  out->size += size;
44
212k
  return 1;
45
217k
}
Unexecuted instantiation: libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
462k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
462k
  size_t newsize;
26
462k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
462k
  if (out->size + size >= out->capacity) {
30
5.34k
    newsize = out->capacity << 1;
31
5.34k
    if (newsize < out->size + size) {
32
1.17k
      newsize = out->size + size;
33
1.17k
    }
34
5.34k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.34k
    out->capacity = newsize;
36
5.34k
  }
37
462k
  if (!out->buf) {
38
4.38k
    out->size = 0;
39
4.38k
    return 0;
40
4.38k
  }
41
42
458k
  memcpy(out->buf + out->size, buffer, size);
43
458k
  out->size += size;
44
458k
  return 1;
45
462k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
28.7k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
28.7k
  size_t newsize;
26
28.7k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
28.7k
  if (out->size + size >= out->capacity) {
30
4.07k
    newsize = out->capacity << 1;
31
4.07k
    if (newsize < out->size + size) {
32
1.35k
      newsize = out->size + size;
33
1.35k
    }
34
4.07k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.07k
    out->capacity = newsize;
36
4.07k
  }
37
28.7k
  if (!out->buf) {
38
2.60k
    out->size = 0;
39
2.60k
    return 0;
40
2.60k
  }
41
42
26.1k
  memcpy(out->buf + out->size, buffer, size);
43
26.1k
  out->size += size;
44
26.1k
  return 1;
45
28.7k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
130k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
130k
  size_t newsize;
26
130k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
130k
  if (out->size + size >= out->capacity) {
30
7.11k
    newsize = out->capacity << 1;
31
7.11k
    if (newsize < out->size + size) {
32
1.62k
      newsize = out->size + size;
33
1.62k
    }
34
7.11k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.11k
    out->capacity = newsize;
36
7.11k
  }
37
130k
  if (!out->buf) {
38
5.05k
    out->size = 0;
39
5.05k
    return 0;
40
5.05k
  }
41
42
125k
  memcpy(out->buf + out->size, buffer, size);
43
125k
  out->size += size;
44
125k
  return 1;
45
130k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
117k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
117k
  size_t newsize;
26
117k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
117k
  if (out->size + size >= out->capacity) {
30
5.82k
    newsize = out->capacity << 1;
31
5.82k
    if (newsize < out->size + size) {
32
1.37k
      newsize = out->size + size;
33
1.37k
    }
34
5.82k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.82k
    out->capacity = newsize;
36
5.82k
  }
37
117k
  if (!out->buf) {
38
4.06k
    out->size = 0;
39
4.06k
    return 0;
40
4.06k
  }
41
42
113k
  memcpy(out->buf + out->size, buffer, size);
43
113k
  out->size += size;
44
113k
  return 1;
45
117k
}
46
47
#endif // YAML_WRITE_HANDLER_H_