Coverage Report

Created: 2025-10-10 06:20

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
840k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
840k
  size_t newsize;
26
840k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
840k
  if (out->size + size >= out->capacity) {
30
27.5k
    newsize = out->capacity << 1;
31
27.5k
    if (newsize < out->size + size) {
32
7.00k
      newsize = out->size + size;
33
7.00k
    }
34
27.5k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
27.5k
    out->capacity = newsize;
36
27.5k
  }
37
840k
  if (!out->buf) {
38
18.8k
    out->size = 0;
39
18.8k
    return 0;
40
18.8k
  }
41
42
821k
  memcpy(out->buf + out->size, buffer, size);
43
821k
  out->size += size;
44
821k
  return 1;
45
840k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
253k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
253k
  size_t newsize;
26
253k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
253k
  if (out->size + size >= out->capacity) {
30
6.25k
    newsize = out->capacity << 1;
31
6.25k
    if (newsize < out->size + size) {
32
1.29k
      newsize = out->size + size;
33
1.29k
    }
34
6.25k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.25k
    out->capacity = newsize;
36
6.25k
  }
37
253k
  if (!out->buf) {
38
4.89k
    out->size = 0;
39
4.89k
    return 0;
40
4.89k
  }
41
42
248k
  memcpy(out->buf + out->size, buffer, size);
43
248k
  out->size += size;
44
248k
  return 1;
45
253k
}
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
44.6k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
44.6k
  size_t newsize;
26
44.6k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
44.6k
  if (out->size + size >= out->capacity) {
30
5.19k
    newsize = out->capacity << 1;
31
5.19k
    if (newsize < out->size + size) {
32
1.63k
      newsize = out->size + size;
33
1.63k
    }
34
5.19k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.19k
    out->capacity = newsize;
36
5.19k
  }
37
44.6k
  if (!out->buf) {
38
2.49k
    out->size = 0;
39
2.49k
    return 0;
40
2.49k
  }
41
42
42.1k
  memcpy(out->buf + out->size, buffer, size);
43
42.1k
  out->size += size;
44
42.1k
  return 1;
45
44.6k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
409k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
409k
  size_t newsize;
26
409k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
409k
  if (out->size + size >= out->capacity) {
30
5.42k
    newsize = out->capacity << 1;
31
5.42k
    if (newsize < out->size + size) {
32
1.17k
      newsize = out->size + size;
33
1.17k
    }
34
5.42k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.42k
    out->capacity = newsize;
36
5.42k
  }
37
409k
  if (!out->buf) {
38
4.15k
    out->size = 0;
39
4.15k
    return 0;
40
4.15k
  }
41
42
405k
  memcpy(out->buf + out->size, buffer, size);
43
405k
  out->size += size;
44
405k
  return 1;
45
409k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
34.3k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
34.3k
  size_t newsize;
26
34.3k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
34.3k
  if (out->size + size >= out->capacity) {
30
3.90k
    newsize = out->capacity << 1;
31
3.90k
    if (newsize < out->size + size) {
32
1.30k
      newsize = out->size + size;
33
1.30k
    }
34
3.90k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
3.90k
    out->capacity = newsize;
36
3.90k
  }
37
34.3k
  if (!out->buf) {
38
2.46k
    out->size = 0;
39
2.46k
    return 0;
40
2.46k
  }
41
42
31.8k
  memcpy(out->buf + out->size, buffer, size);
43
31.8k
  out->size += size;
44
31.8k
  return 1;
45
34.3k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
98.2k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
98.2k
  size_t newsize;
26
98.2k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
98.2k
  if (out->size + size >= out->capacity) {
30
6.79k
    newsize = out->capacity << 1;
31
6.79k
    if (newsize < out->size + size) {
32
1.59k
      newsize = out->size + size;
33
1.59k
    }
34
6.79k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.79k
    out->capacity = newsize;
36
6.79k
  }
37
98.2k
  if (!out->buf) {
38
4.88k
    out->size = 0;
39
4.88k
    return 0;
40
4.88k
  }
41
42
93.4k
  memcpy(out->buf + out->size, buffer, size);
43
93.4k
  out->size += size;
44
93.4k
  return 1;
45
98.2k
}
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler
46
47
#endif // YAML_WRITE_HANDLER_H_