Coverage Report

Created: 2026-07-30 06:36

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
936k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
936k
  size_t newsize;
26
936k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
936k
  if (out->size + size >= out->capacity) {
30
24.6k
    newsize = out->capacity << 1;
31
24.6k
    if (newsize < out->size + size) {
32
5.46k
      newsize = out->size + size;
33
5.46k
    }
34
24.6k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
24.6k
    out->capacity = newsize;
36
24.6k
  }
37
936k
  if (!out->buf) {
38
18.3k
    out->size = 0;
39
18.3k
    return 0;
40
18.3k
  }
41
42
918k
  memcpy(out->buf + out->size, buffer, size);
43
918k
  out->size += size;
44
918k
  return 1;
45
936k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
211k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
211k
  size_t newsize;
26
211k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
211k
  if (out->size + size >= out->capacity) {
30
6.13k
    newsize = out->capacity << 1;
31
6.13k
    if (newsize < out->size + size) {
32
1.26k
      newsize = out->size + size;
33
1.26k
    }
34
6.13k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.13k
    out->capacity = newsize;
36
6.13k
  }
37
211k
  if (!out->buf) {
38
4.91k
    out->size = 0;
39
4.91k
    return 0;
40
4.91k
  }
41
42
206k
  memcpy(out->buf + out->size, buffer, size);
43
206k
  out->size += size;
44
206k
  return 1;
45
211k
}
Unexecuted instantiation: libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
440k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
440k
  size_t newsize;
26
440k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
440k
  if (out->size + size >= out->capacity) {
30
5.38k
    newsize = out->capacity << 1;
31
5.38k
    if (newsize < out->size + size) {
32
1.17k
      newsize = out->size + size;
33
1.17k
    }
34
5.38k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.38k
    out->capacity = newsize;
36
5.38k
  }
37
440k
  if (!out->buf) {
38
4.33k
    out->size = 0;
39
4.33k
    return 0;
40
4.33k
  }
41
42
435k
  memcpy(out->buf + out->size, buffer, size);
43
435k
  out->size += size;
44
435k
  return 1;
45
440k
}
Unexecuted instantiation: libyaml_deconstructor_fuzzer.c:yaml_write_handler
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
153k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
153k
  size_t newsize;
26
153k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
153k
  if (out->size + size >= out->capacity) {
30
6.01k
    newsize = out->capacity << 1;
31
6.01k
    if (newsize < out->size + size) {
32
1.40k
      newsize = out->size + size;
33
1.40k
    }
34
6.01k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.01k
    out->capacity = newsize;
36
6.01k
  }
37
153k
  if (!out->buf) {
38
4.08k
    out->size = 0;
39
4.08k
    return 0;
40
4.08k
  }
41
42
149k
  memcpy(out->buf + out->size, buffer, size);
43
149k
  out->size += size;
44
149k
  return 1;
45
153k
}
46
47
#endif // YAML_WRITE_HANDLER_H_