Coverage Report

Created: 2026-06-15 06:35

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
941k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
941k
  size_t newsize;
26
941k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
941k
  if (out->size + size >= out->capacity) {
30
28.6k
    newsize = out->capacity << 1;
31
28.6k
    if (newsize < out->size + size) {
32
6.81k
      newsize = out->size + size;
33
6.81k
    }
34
28.6k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.6k
    out->capacity = newsize;
36
28.6k
  }
37
941k
  if (!out->buf) {
38
21.2k
    out->size = 0;
39
21.2k
    return 0;
40
21.2k
  }
41
42
920k
  memcpy(out->buf + out->size, buffer, size);
43
920k
  out->size += size;
44
920k
  return 1;
45
941k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
243k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
243k
  size_t newsize;
26
243k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
243k
  if (out->size + size >= out->capacity) {
30
6.30k
    newsize = out->capacity << 1;
31
6.30k
    if (newsize < out->size + size) {
32
1.28k
      newsize = out->size + size;
33
1.28k
    }
34
6.30k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.30k
    out->capacity = newsize;
36
6.30k
  }
37
243k
  if (!out->buf) {
38
5.06k
    out->size = 0;
39
5.06k
    return 0;
40
5.06k
  }
41
42
237k
  memcpy(out->buf + out->size, buffer, size);
43
237k
  out->size += size;
44
237k
  return 1;
45
243k
}
Unexecuted instantiation: libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
385k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
385k
  size_t newsize;
26
385k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
385k
  if (out->size + size >= out->capacity) {
30
5.44k
    newsize = out->capacity << 1;
31
5.44k
    if (newsize < out->size + size) {
32
1.18k
      newsize = out->size + size;
33
1.18k
    }
34
5.44k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.44k
    out->capacity = newsize;
36
5.44k
  }
37
385k
  if (!out->buf) {
38
4.33k
    out->size = 0;
39
4.33k
    return 0;
40
4.33k
  }
41
42
381k
  memcpy(out->buf + out->size, buffer, size);
43
381k
  out->size += size;
44
381k
  return 1;
45
385k
}
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
152k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
152k
  size_t newsize;
26
152k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
152k
  if (out->size + size >= out->capacity) {
30
5.72k
    newsize = out->capacity << 1;
31
5.72k
    if (newsize < out->size + size) {
32
1.36k
      newsize = out->size + size;
33
1.36k
    }
34
5.72k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.72k
    out->capacity = newsize;
36
5.72k
  }
37
152k
  if (!out->buf) {
38
4.18k
    out->size = 0;
39
4.18k
    return 0;
40
4.18k
  }
41
42
148k
  memcpy(out->buf + out->size, buffer, size);
43
148k
  out->size += size;
44
148k
  return 1;
45
152k
}
46
47
#endif // YAML_WRITE_HANDLER_H_