Coverage Report

Created: 2026-07-16 06:23

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
964k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
964k
  size_t newsize;
26
964k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
964k
  if (out->size + size >= out->capacity) {
30
28.6k
    newsize = out->capacity << 1;
31
28.6k
    if (newsize < out->size + size) {
32
6.82k
      newsize = out->size + size;
33
6.82k
    }
34
28.6k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.6k
    out->capacity = newsize;
36
28.6k
  }
37
964k
  if (!out->buf) {
38
20.9k
    out->size = 0;
39
20.9k
    return 0;
40
20.9k
  }
41
42
943k
  memcpy(out->buf + out->size, buffer, size);
43
943k
  out->size += size;
44
943k
  return 1;
45
964k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
216k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
216k
  size_t newsize;
26
216k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
216k
  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
216k
  if (!out->buf) {
38
4.88k
    out->size = 0;
39
4.88k
    return 0;
40
4.88k
  }
41
42
211k
  memcpy(out->buf + out->size, buffer, size);
43
211k
  out->size += size;
44
211k
  return 1;
45
216k
}
Unexecuted instantiation: libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
471k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
471k
  size_t newsize;
26
471k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
471k
  if (out->size + size >= out->capacity) {
30
5.39k
    newsize = out->capacity << 1;
31
5.39k
    if (newsize < out->size + size) {
32
1.18k
      newsize = out->size + size;
33
1.18k
    }
34
5.39k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.39k
    out->capacity = newsize;
36
5.39k
  }
37
471k
  if (!out->buf) {
38
4.37k
    out->size = 0;
39
4.37k
    return 0;
40
4.37k
  }
41
42
466k
  memcpy(out->buf + out->size, buffer, size);
43
466k
  out->size += size;
44
466k
  return 1;
45
471k
}
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.88k
    newsize = out->capacity << 1;
31
5.88k
    if (newsize < out->size + size) {
32
1.39k
      newsize = out->size + size;
33
1.39k
    }
34
5.88k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.88k
    out->capacity = newsize;
36
5.88k
  }
37
117k
  if (!out->buf) {
38
4.02k
    out->size = 0;
39
4.02k
    return 0;
40
4.02k
  }
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_