Coverage Report

Created: 2026-01-17 06:58

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
847k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
847k
  size_t newsize;
26
847k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
847k
  if (out->size + size >= out->capacity) {
30
28.3k
    newsize = out->capacity << 1;
31
28.3k
    if (newsize < out->size + size) {
32
7.16k
      newsize = out->size + size;
33
7.16k
    }
34
28.3k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.3k
    out->capacity = newsize;
36
28.3k
  }
37
847k
  if (!out->buf) {
38
19.0k
    out->size = 0;
39
19.0k
    return 0;
40
19.0k
  }
41
42
828k
  memcpy(out->buf + out->size, buffer, size);
43
828k
  out->size += size;
44
828k
  return 1;
45
847k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
254k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
254k
  size_t newsize;
26
254k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
254k
  if (out->size + size >= out->capacity) {
30
6.42k
    newsize = out->capacity << 1;
31
6.42k
    if (newsize < out->size + size) {
32
1.32k
      newsize = out->size + size;
33
1.32k
    }
34
6.42k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.42k
    out->capacity = newsize;
36
6.42k
  }
37
254k
  if (!out->buf) {
38
4.95k
    out->size = 0;
39
4.95k
    return 0;
40
4.95k
  }
41
42
249k
  memcpy(out->buf + out->size, buffer, size);
43
249k
  out->size += size;
44
249k
  return 1;
45
254k
}
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
48.0k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
48.0k
  size_t newsize;
26
48.0k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
48.0k
  if (out->size + size >= out->capacity) {
30
5.27k
    newsize = out->capacity << 1;
31
5.27k
    if (newsize < out->size + size) {
32
1.67k
      newsize = out->size + size;
33
1.67k
    }
34
5.27k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.27k
    out->capacity = newsize;
36
5.27k
  }
37
48.0k
  if (!out->buf) {
38
2.53k
    out->size = 0;
39
2.53k
    return 0;
40
2.53k
  }
41
42
45.5k
  memcpy(out->buf + out->size, buffer, size);
43
45.5k
  out->size += size;
44
45.5k
  return 1;
45
48.0k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
407k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
407k
  size_t newsize;
26
407k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
407k
  if (out->size + size >= out->capacity) {
30
5.63k
    newsize = out->capacity << 1;
31
5.63k
    if (newsize < out->size + size) {
32
1.19k
      newsize = out->size + size;
33
1.19k
    }
34
5.63k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.63k
    out->capacity = newsize;
36
5.63k
  }
37
407k
  if (!out->buf) {
38
4.19k
    out->size = 0;
39
4.19k
    return 0;
40
4.19k
  }
41
42
402k
  memcpy(out->buf + out->size, buffer, size);
43
402k
  out->size += size;
44
402k
  return 1;
45
407k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
33.9k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
33.9k
  size_t newsize;
26
33.9k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
33.9k
  if (out->size + size >= out->capacity) {
30
4.00k
    newsize = out->capacity << 1;
31
4.00k
    if (newsize < out->size + size) {
32
1.32k
      newsize = out->size + size;
33
1.32k
    }
34
4.00k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.00k
    out->capacity = newsize;
36
4.00k
  }
37
33.9k
  if (!out->buf) {
38
2.49k
    out->size = 0;
39
2.49k
    return 0;
40
2.49k
  }
41
42
31.4k
  memcpy(out->buf + out->size, buffer, size);
43
31.4k
  out->size += size;
44
31.4k
  return 1;
45
33.9k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
103k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
103k
  size_t newsize;
26
103k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
103k
  if (out->size + size >= out->capacity) {
30
6.99k
    newsize = out->capacity << 1;
31
6.99k
    if (newsize < out->size + size) {
32
1.64k
      newsize = out->size + size;
33
1.64k
    }
34
6.99k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.99k
    out->capacity = newsize;
36
6.99k
  }
37
103k
  if (!out->buf) {
38
4.90k
    out->size = 0;
39
4.90k
    return 0;
40
4.90k
  }
41
42
98.8k
  memcpy(out->buf + out->size, buffer, size);
43
98.8k
  out->size += size;
44
98.8k
  return 1;
45
103k
}
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler
46
47
#endif // YAML_WRITE_HANDLER_H_