Coverage Report

Created: 2026-04-12 06:04

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
897k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
897k
  size_t newsize;
26
897k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
897k
  if (out->size + size >= out->capacity) {
30
34.1k
    newsize = out->capacity << 1;
31
34.1k
    if (newsize < out->size + size) {
32
8.62k
      newsize = out->size + size;
33
8.62k
    }
34
34.1k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
34.1k
    out->capacity = newsize;
36
34.1k
  }
37
897k
  if (!out->buf) {
38
23.2k
    out->size = 0;
39
23.2k
    return 0;
40
23.2k
  }
41
42
874k
  memcpy(out->buf + out->size, buffer, size);
43
874k
  out->size += size;
44
874k
  return 1;
45
897k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
251k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
251k
  size_t newsize;
26
251k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
251k
  if (out->size + size >= out->capacity) {
30
6.48k
    newsize = out->capacity << 1;
31
6.48k
    if (newsize < out->size + size) {
32
1.32k
      newsize = out->size + size;
33
1.32k
    }
34
6.48k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.48k
    out->capacity = newsize;
36
6.48k
  }
37
251k
  if (!out->buf) {
38
5.10k
    out->size = 0;
39
5.10k
    return 0;
40
5.10k
  }
41
42
246k
  memcpy(out->buf + out->size, buffer, size);
43
246k
  out->size += size;
44
246k
  return 1;
45
251k
}
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
393k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
393k
  size_t newsize;
26
393k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
393k
  if (out->size + size >= out->capacity) {
30
5.66k
    newsize = out->capacity << 1;
31
5.66k
    if (newsize < out->size + size) {
32
1.23k
      newsize = out->size + size;
33
1.23k
    }
34
5.66k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.66k
    out->capacity = newsize;
36
5.66k
  }
37
393k
  if (!out->buf) {
38
4.29k
    out->size = 0;
39
4.29k
    return 0;
40
4.29k
  }
41
42
389k
  memcpy(out->buf + out->size, buffer, size);
43
389k
  out->size += size;
44
389k
  return 1;
45
393k
}
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.06k
    newsize = out->capacity << 1;
31
4.06k
    if (newsize < out->size + size) {
32
1.35k
      newsize = out->size + size;
33
1.35k
    }
34
4.06k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.06k
    out->capacity = newsize;
36
4.06k
  }
37
29.1k
  if (!out->buf) {
38
2.58k
    out->size = 0;
39
2.58k
    return 0;
40
2.58k
  }
41
42
26.5k
  memcpy(out->buf + out->size, buffer, size);
43
26.5k
  out->size += size;
44
26.5k
  return 1;
45
29.1k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
95.4k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
95.4k
  size_t newsize;
26
95.4k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
95.4k
  if (out->size + size >= out->capacity) {
30
7.12k
    newsize = out->capacity << 1;
31
7.12k
    if (newsize < out->size + size) {
32
1.66k
      newsize = out->size + size;
33
1.66k
    }
34
7.12k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.12k
    out->capacity = newsize;
36
7.12k
  }
37
95.4k
  if (!out->buf) {
38
5.09k
    out->size = 0;
39
5.09k
    return 0;
40
5.09k
  }
41
42
90.3k
  memcpy(out->buf + out->size, buffer, size);
43
90.3k
  out->size += size;
44
90.3k
  return 1;
45
95.4k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
90.8k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
90.8k
  size_t newsize;
26
90.8k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
90.8k
  if (out->size + size >= out->capacity) {
30
5.69k
    newsize = out->capacity << 1;
31
5.69k
    if (newsize < out->size + size) {
32
1.36k
      newsize = out->size + size;
33
1.36k
    }
34
5.69k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.69k
    out->capacity = newsize;
36
5.69k
  }
37
90.8k
  if (!out->buf) {
38
3.62k
    out->size = 0;
39
3.62k
    return 0;
40
3.62k
  }
41
42
87.2k
  memcpy(out->buf + out->size, buffer, size);
43
87.2k
  out->size += size;
44
87.2k
  return 1;
45
90.8k
}
46
47
#endif // YAML_WRITE_HANDLER_H_