Coverage Report

Created: 2026-02-26 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
793k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
793k
  size_t newsize;
26
793k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
793k
  if (out->size + size >= out->capacity) {
30
28.1k
    newsize = out->capacity << 1;
31
28.1k
    if (newsize < out->size + size) {
32
7.19k
      newsize = out->size + size;
33
7.19k
    }
34
28.1k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.1k
    out->capacity = newsize;
36
28.1k
  }
37
793k
  if (!out->buf) {
38
19.2k
    out->size = 0;
39
19.2k
    return 0;
40
19.2k
  }
41
42
773k
  memcpy(out->buf + out->size, buffer, size);
43
773k
  out->size += size;
44
773k
  return 1;
45
793k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
248k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
248k
  size_t newsize;
26
248k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
248k
  if (out->size + size >= out->capacity) {
30
6.39k
    newsize = out->capacity << 1;
31
6.39k
    if (newsize < out->size + size) {
32
1.32k
      newsize = out->size + size;
33
1.32k
    }
34
6.39k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.39k
    out->capacity = newsize;
36
6.39k
  }
37
248k
  if (!out->buf) {
38
4.96k
    out->size = 0;
39
4.96k
    return 0;
40
4.96k
  }
41
42
243k
  memcpy(out->buf + out->size, buffer, size);
43
243k
  out->size += size;
44
243k
  return 1;
45
248k
}
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
36.8k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
36.8k
  size_t newsize;
26
36.8k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
36.8k
  if (out->size + size >= out->capacity) {
30
5.16k
    newsize = out->capacity << 1;
31
5.16k
    if (newsize < out->size + size) {
32
1.68k
      newsize = out->size + size;
33
1.68k
    }
34
5.16k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.16k
    out->capacity = newsize;
36
5.16k
  }
37
36.8k
  if (!out->buf) {
38
2.59k
    out->size = 0;
39
2.59k
    return 0;
40
2.59k
  }
41
42
34.2k
  memcpy(out->buf + out->size, buffer, size);
43
34.2k
  out->size += size;
44
34.2k
  return 1;
45
36.8k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
401k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
401k
  size_t newsize;
26
401k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
401k
  if (out->size + size >= out->capacity) {
30
5.61k
    newsize = out->capacity << 1;
31
5.61k
    if (newsize < out->size + size) {
32
1.20k
      newsize = out->size + size;
33
1.20k
    }
34
5.61k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.61k
    out->capacity = newsize;
36
5.61k
  }
37
401k
  if (!out->buf) {
38
4.19k
    out->size = 0;
39
4.19k
    return 0;
40
4.19k
  }
41
42
397k
  memcpy(out->buf + out->size, buffer, size);
43
397k
  out->size += size;
44
397k
  return 1;
45
401k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
29.2k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
29.2k
  size_t newsize;
26
29.2k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
29.2k
  if (out->size + size >= out->capacity) {
30
4.00k
    newsize = out->capacity << 1;
31
4.00k
    if (newsize < out->size + size) {
32
1.33k
      newsize = out->size + size;
33
1.33k
    }
34
4.00k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.00k
    out->capacity = newsize;
36
4.00k
  }
37
29.2k
  if (!out->buf) {
38
2.54k
    out->size = 0;
39
2.54k
    return 0;
40
2.54k
  }
41
42
26.6k
  memcpy(out->buf + out->size, buffer, size);
43
26.6k
  out->size += size;
44
26.6k
  return 1;
45
29.2k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
77.2k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
77.2k
  size_t newsize;
26
77.2k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
77.2k
  if (out->size + size >= out->capacity) {
30
6.94k
    newsize = out->capacity << 1;
31
6.94k
    if (newsize < out->size + size) {
32
1.64k
      newsize = out->size + size;
33
1.64k
    }
34
6.94k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.94k
    out->capacity = newsize;
36
6.94k
  }
37
77.2k
  if (!out->buf) {
38
4.97k
    out->size = 0;
39
4.97k
    return 0;
40
4.97k
  }
41
42
72.2k
  memcpy(out->buf + out->size, buffer, size);
43
72.2k
  out->size += size;
44
72.2k
  return 1;
45
77.2k
}
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler
46
47
#endif // YAML_WRITE_HANDLER_H_