Coverage Report

Created: 2026-03-11 07:02

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
803k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
803k
  size_t newsize;
26
803k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
803k
  if (out->size + size >= out->capacity) {
30
30.0k
    newsize = out->capacity << 1;
31
30.0k
    if (newsize < out->size + size) {
32
7.81k
      newsize = out->size + size;
33
7.81k
    }
34
30.0k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
30.0k
    out->capacity = newsize;
36
30.0k
  }
37
803k
  if (!out->buf) {
38
20.2k
    out->size = 0;
39
20.2k
    return 0;
40
20.2k
  }
41
42
783k
  memcpy(out->buf + out->size, buffer, size);
43
783k
  out->size += size;
44
783k
  return 1;
45
803k
}
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.38k
    newsize = out->capacity << 1;
31
6.38k
    if (newsize < out->size + size) {
32
1.31k
      newsize = out->size + size;
33
1.31k
    }
34
6.38k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.38k
    out->capacity = newsize;
36
6.38k
  }
37
248k
  if (!out->buf) {
38
4.98k
    out->size = 0;
39
4.98k
    return 0;
40
4.98k
  }
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
399k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
399k
  size_t newsize;
26
399k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
399k
  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
399k
  if (!out->buf) {
38
4.22k
    out->size = 0;
39
4.22k
    return 0;
40
4.22k
  }
41
42
395k
  memcpy(out->buf + out->size, buffer, size);
43
395k
  out->size += size;
44
395k
  return 1;
45
399k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
29.1k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
29.1k
  size_t newsize;
26
29.1k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
29.1k
  if (out->size + size >= out->capacity) {
30
4.02k
    newsize = out->capacity << 1;
31
4.02k
    if (newsize < out->size + size) {
32
1.34k
      newsize = out->size + size;
33
1.34k
    }
34
4.02k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.02k
    out->capacity = newsize;
36
4.02k
  }
37
29.1k
  if (!out->buf) {
38
2.50k
    out->size = 0;
39
2.50k
    return 0;
40
2.50k
  }
41
42
26.6k
  memcpy(out->buf + out->size, buffer, size);
43
26.6k
  out->size += size;
44
26.6k
  return 1;
45
29.1k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
79.6k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
79.6k
  size_t newsize;
26
79.6k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
79.6k
  if (out->size + size >= out->capacity) {
30
7.03k
    newsize = out->capacity << 1;
31
7.03k
    if (newsize < out->size + size) {
32
1.66k
      newsize = out->size + size;
33
1.66k
    }
34
7.03k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.03k
    out->capacity = newsize;
36
7.03k
  }
37
79.6k
  if (!out->buf) {
38
4.99k
    out->size = 0;
39
4.99k
    return 0;
40
4.99k
  }
41
42
74.6k
  memcpy(out->buf + out->size, buffer, size);
43
74.6k
  out->size += size;
44
74.6k
  return 1;
45
79.6k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
10.0k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
10.0k
  size_t newsize;
26
10.0k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
10.0k
  if (out->size + size >= out->capacity) {
30
1.81k
    newsize = out->capacity << 1;
31
1.81k
    if (newsize < out->size + size) {
32
607
      newsize = out->size + size;
33
607
    }
34
1.81k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
1.81k
    out->capacity = newsize;
36
1.81k
  }
37
10.0k
  if (!out->buf) {
38
899
    out->size = 0;
39
899
    return 0;
40
899
  }
41
42
9.13k
  memcpy(out->buf + out->size, buffer, size);
43
9.13k
  out->size += size;
44
9.13k
  return 1;
45
10.0k
}
46
47
#endif // YAML_WRITE_HANDLER_H_