Coverage Report

Created: 2026-01-09 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
855k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
855k
  size_t newsize;
26
855k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
855k
  if (out->size + size >= out->capacity) {
30
28.2k
    newsize = out->capacity << 1;
31
28.2k
    if (newsize < out->size + size) {
32
7.15k
      newsize = out->size + size;
33
7.15k
    }
34
28.2k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
28.2k
    out->capacity = newsize;
36
28.2k
  }
37
855k
  if (!out->buf) {
38
19.1k
    out->size = 0;
39
19.1k
    return 0;
40
19.1k
  }
41
42
835k
  memcpy(out->buf + out->size, buffer, size);
43
835k
  out->size += size;
44
835k
  return 1;
45
855k
}
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
45.9k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
45.9k
  size_t newsize;
26
45.9k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
45.9k
  if (out->size + size >= out->capacity) {
30
5.20k
    newsize = out->capacity << 1;
31
5.20k
    if (newsize < out->size + size) {
32
1.66k
      newsize = out->size + size;
33
1.66k
    }
34
5.20k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.20k
    out->capacity = newsize;
36
5.20k
  }
37
45.9k
  if (!out->buf) {
38
2.54k
    out->size = 0;
39
2.54k
    return 0;
40
2.54k
  }
41
42
43.4k
  memcpy(out->buf + out->size, buffer, size);
43
43.4k
  out->size += size;
44
43.4k
  return 1;
45
45.9k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
418k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
418k
  size_t newsize;
26
418k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
418k
  if (out->size + size >= out->capacity) {
30
5.67k
    newsize = out->capacity << 1;
31
5.67k
    if (newsize < out->size + size) {
32
1.20k
      newsize = out->size + size;
33
1.20k
    }
34
5.67k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.67k
    out->capacity = newsize;
36
5.67k
  }
37
418k
  if (!out->buf) {
38
4.21k
    out->size = 0;
39
4.21k
    return 0;
40
4.21k
  }
41
42
414k
  memcpy(out->buf + out->size, buffer, size);
43
414k
  out->size += size;
44
414k
  return 1;
45
418k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
34.0k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
34.0k
  size_t newsize;
26
34.0k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
34.0k
  if (out->size + size >= out->capacity) {
30
4.01k
    newsize = out->capacity << 1;
31
4.01k
    if (newsize < out->size + size) {
32
1.33k
      newsize = out->size + size;
33
1.33k
    }
34
4.01k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.01k
    out->capacity = newsize;
36
4.01k
  }
37
34.0k
  if (!out->buf) {
38
2.54k
    out->size = 0;
39
2.54k
    return 0;
40
2.54k
  }
41
42
31.5k
  memcpy(out->buf + out->size, buffer, size);
43
31.5k
  out->size += size;
44
31.5k
  return 1;
45
34.0k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
101k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
101k
  size_t newsize;
26
101k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
101k
  if (out->size + size >= out->capacity) {
30
6.96k
    newsize = out->capacity << 1;
31
6.96k
    if (newsize < out->size + size) {
32
1.63k
      newsize = out->size + size;
33
1.63k
    }
34
6.96k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.96k
    out->capacity = newsize;
36
6.96k
  }
37
101k
  if (!out->buf) {
38
4.93k
    out->size = 0;
39
4.93k
    return 0;
40
4.93k
  }
41
42
96.5k
  memcpy(out->buf + out->size, buffer, size);
43
96.5k
  out->size += size;
44
96.5k
  return 1;
45
101k
}
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler
46
47
#endif // YAML_WRITE_HANDLER_H_