Coverage Report

Created: 2026-01-25 06:56

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
844k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
844k
  size_t newsize;
26
844k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
844k
  if (out->size + size >= out->capacity) {
30
28.3k
    newsize = out->capacity << 1;
31
28.3k
    if (newsize < out->size + size) {
32
7.18k
      newsize = out->size + size;
33
7.18k
    }
34
28.3k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.3k
    out->capacity = newsize;
36
28.3k
  }
37
844k
  if (!out->buf) {
38
19.1k
    out->size = 0;
39
19.1k
    return 0;
40
19.1k
  }
41
42
825k
  memcpy(out->buf + out->size, buffer, size);
43
825k
  out->size += size;
44
825k
  return 1;
45
844k
}
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.33k
      newsize = out->size + size;
33
1.33k
    }
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.99k
    out->size = 0;
39
4.99k
    return 0;
40
4.99k
  }
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
46.3k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
46.3k
  size_t newsize;
26
46.3k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
46.3k
  if (out->size + size >= out->capacity) {
30
5.25k
    newsize = out->capacity << 1;
31
5.25k
    if (newsize < out->size + size) {
32
1.67k
      newsize = out->size + size;
33
1.67k
    }
34
5.25k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.25k
    out->capacity = newsize;
36
5.25k
  }
37
46.3k
  if (!out->buf) {
38
2.53k
    out->size = 0;
39
2.53k
    return 0;
40
2.53k
  }
41
42
43.8k
  memcpy(out->buf + out->size, buffer, size);
43
43.8k
  out->size += size;
44
43.8k
  return 1;
45
46.3k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
406k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
406k
  size_t newsize;
26
406k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
406k
  if (out->size + size >= out->capacity) {
30
5.66k
    newsize = out->capacity << 1;
31
5.66k
    if (newsize < out->size + size) {
32
1.20k
      newsize = out->size + size;
33
1.20k
    }
34
5.66k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.66k
    out->capacity = newsize;
36
5.66k
  }
37
406k
  if (!out->buf) {
38
4.20k
    out->size = 0;
39
4.20k
    return 0;
40
4.20k
  }
41
42
401k
  memcpy(out->buf + out->size, buffer, size);
43
401k
  out->size += size;
44
401k
  return 1;
45
406k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
33.6k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
33.6k
  size_t newsize;
26
33.6k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
33.6k
  if (out->size + size >= out->capacity) {
30
3.99k
    newsize = out->capacity << 1;
31
3.99k
    if (newsize < out->size + size) {
32
1.33k
      newsize = out->size + size;
33
1.33k
    }
34
3.99k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
3.99k
    out->capacity = newsize;
36
3.99k
  }
37
33.6k
  if (!out->buf) {
38
2.50k
    out->size = 0;
39
2.50k
    return 0;
40
2.50k
  }
41
42
31.1k
  memcpy(out->buf + out->size, buffer, size);
43
31.1k
  out->size += size;
44
31.1k
  return 1;
45
33.6k
}
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
7.00k
    newsize = out->capacity << 1;
31
7.00k
    if (newsize < out->size + size) {
32
1.64k
      newsize = out->size + size;
33
1.64k
    }
34
7.00k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.00k
    out->capacity = newsize;
36
7.00k
  }
37
103k
  if (!out->buf) {
38
4.93k
    out->size = 0;
39
4.93k
    return 0;
40
4.93k
  }
41
42
98.9k
  memcpy(out->buf + out->size, buffer, size);
43
98.9k
  out->size += size;
44
98.9k
  return 1;
45
103k
}
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler
46
47
#endif // YAML_WRITE_HANDLER_H_