Coverage Report

Created: 2025-08-03 06:14

/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
772k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
772k
  size_t newsize;
26
772k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
772k
  if (out->size + size >= out->capacity) {
30
27.2k
    newsize = out->capacity << 1;
31
27.2k
    if (newsize < out->size + size) {
32
6.94k
      newsize = out->size + size;
33
6.94k
    }
34
27.2k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
27.2k
    out->capacity = newsize;
36
27.2k
  }
37
772k
  if (!out->buf) {
38
19.2k
    out->size = 0;
39
19.2k
    return 0;
40
19.2k
  }
41
42
753k
  memcpy(out->buf + out->size, buffer, size);
43
753k
  out->size += size;
44
753k
  return 1;
45
772k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
249k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
249k
  size_t newsize;
26
249k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
249k
  if (out->size + size >= out->capacity) {
30
6.07k
    newsize = out->capacity << 1;
31
6.07k
    if (newsize < out->size + size) {
32
1.25k
      newsize = out->size + size;
33
1.25k
    }
34
6.07k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.07k
    out->capacity = newsize;
36
6.07k
  }
37
249k
  if (!out->buf) {
38
4.97k
    out->size = 0;
39
4.97k
    return 0;
40
4.97k
  }
41
42
244k
  memcpy(out->buf + out->size, buffer, size);
43
244k
  out->size += size;
44
244k
  return 1;
45
249k
}
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
42.1k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
42.1k
  size_t newsize;
26
42.1k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
42.1k
  if (out->size + size >= out->capacity) {
30
5.07k
    newsize = out->capacity << 1;
31
5.07k
    if (newsize < out->size + size) {
32
1.60k
      newsize = out->size + size;
33
1.60k
    }
34
5.07k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.07k
    out->capacity = newsize;
36
5.07k
  }
37
42.1k
  if (!out->buf) {
38
2.52k
    out->size = 0;
39
2.52k
    return 0;
40
2.52k
  }
41
42
39.6k
  memcpy(out->buf + out->size, buffer, size);
43
39.6k
  out->size += size;
44
39.6k
  return 1;
45
42.1k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
292k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
292k
  size_t newsize;
26
292k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
292k
  if (out->size + size >= out->capacity) {
30
5.29k
    newsize = out->capacity << 1;
31
5.29k
    if (newsize < out->size + size) {
32
1.15k
      newsize = out->size + size;
33
1.15k
    }
34
5.29k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.29k
    out->capacity = newsize;
36
5.29k
  }
37
292k
  if (!out->buf) {
38
4.26k
    out->size = 0;
39
4.26k
    return 0;
40
4.26k
  }
41
42
288k
  memcpy(out->buf + out->size, buffer, size);
43
288k
  out->size += size;
44
288k
  return 1;
45
292k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
34.7k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
34.7k
  size_t newsize;
26
34.7k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
34.7k
  if (out->size + size >= out->capacity) {
30
3.88k
    newsize = out->capacity << 1;
31
3.88k
    if (newsize < out->size + size) {
32
1.28k
      newsize = out->size + size;
33
1.28k
    }
34
3.88k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
3.88k
    out->capacity = newsize;
36
3.88k
  }
37
34.7k
  if (!out->buf) {
38
2.55k
    out->size = 0;
39
2.55k
    return 0;
40
2.55k
  }
41
42
32.2k
  memcpy(out->buf + out->size, buffer, size);
43
32.2k
  out->size += size;
44
32.2k
  return 1;
45
34.7k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
153k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
153k
  size_t newsize;
26
153k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
153k
  if (out->size + size >= out->capacity) {
30
6.93k
    newsize = out->capacity << 1;
31
6.93k
    if (newsize < out->size + size) {
32
1.64k
      newsize = out->size + size;
33
1.64k
    }
34
6.93k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.93k
    out->capacity = newsize;
36
6.93k
  }
37
153k
  if (!out->buf) {
38
4.92k
    out->size = 0;
39
4.92k
    return 0;
40
4.92k
  }
41
42
148k
  memcpy(out->buf + out->size, buffer, size);
43
148k
  out->size += size;
44
148k
  return 1;
45
153k
}
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler
46
47
#endif // YAML_WRITE_HANDLER_H_