Coverage Report

Created: 2026-10-13 06:15

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
1.15M
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
1.15M
  size_t newsize;
26
1.15M
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
1.15M
  if (out->size + size >= out->capacity) {
30
33.7k
    newsize = out->capacity << 1;
31
33.7k
    if (newsize < out->size + size) {
32
8.35k
      newsize = out->size + size;
33
8.35k
    }
34
33.7k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
33.7k
    out->capacity = newsize;
36
33.7k
  }
37
1.15M
  if (!out->buf) {
38
22.9k
    out->size = 0;
39
22.9k
    return 0;
40
22.9k
  }
41
42
1.13M
  memcpy(out->buf + out->size, buffer, size);
43
1.13M
  out->size += size;
44
1.13M
  return 1;
45
1.15M
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
311k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
311k
  size_t newsize;
26
311k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
311k
  if (out->size + size >= out->capacity) {
30
6.19k
    newsize = out->capacity << 1;
31
6.19k
    if (newsize < out->size + size) {
32
1.27k
      newsize = out->size + size;
33
1.27k
    }
34
6.19k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.19k
    out->capacity = newsize;
36
6.19k
  }
37
311k
  if (!out->buf) {
38
4.93k
    out->size = 0;
39
4.93k
    return 0;
40
4.93k
  }
41
42
306k
  memcpy(out->buf + out->size, buffer, size);
43
306k
  out->size += size;
44
306k
  return 1;
45
311k
}
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
36.7k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
36.7k
  size_t newsize;
26
36.7k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
36.7k
  if (out->size + size >= out->capacity) {
30
4.90k
    newsize = out->capacity << 1;
31
4.90k
    if (newsize < out->size + size) {
32
1.58k
      newsize = out->size + size;
33
1.58k
    }
34
4.90k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.90k
    out->capacity = newsize;
36
4.90k
  }
37
36.7k
  if (!out->buf) {
38
2.42k
    out->size = 0;
39
2.42k
    return 0;
40
2.42k
  }
41
42
34.3k
  memcpy(out->buf + out->size, buffer, size);
43
34.3k
  out->size += size;
44
34.3k
  return 1;
45
36.7k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
457k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
457k
  size_t newsize;
26
457k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
457k
  if (out->size + size >= out->capacity) {
30
5.51k
    newsize = out->capacity << 1;
31
5.51k
    if (newsize < out->size + size) {
32
1.22k
      newsize = out->size + size;
33
1.22k
    }
34
5.51k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.51k
    out->capacity = newsize;
36
5.51k
  }
37
457k
  if (!out->buf) {
38
4.32k
    out->size = 0;
39
4.32k
    return 0;
40
4.32k
  }
41
42
453k
  memcpy(out->buf + out->size, buffer, size);
43
453k
  out->size += size;
44
453k
  return 1;
45
457k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
29.0k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
29.0k
  size_t newsize;
26
29.0k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
29.0k
  if (out->size + size >= out->capacity) {
30
3.89k
    newsize = out->capacity << 1;
31
3.89k
    if (newsize < out->size + size) {
32
1.24k
      newsize = out->size + size;
33
1.24k
    }
34
3.89k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
3.89k
    out->capacity = newsize;
36
3.89k
  }
37
29.0k
  if (!out->buf) {
38
2.48k
    out->size = 0;
39
2.48k
    return 0;
40
2.48k
  }
41
42
26.5k
  memcpy(out->buf + out->size, buffer, size);
43
26.5k
  out->size += size;
44
26.5k
  return 1;
45
29.0k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
139k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
139k
  size_t newsize;
26
139k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
139k
  if (out->size + size >= out->capacity) {
30
6.87k
    newsize = out->capacity << 1;
31
6.87k
    if (newsize < out->size + size) {
32
1.56k
      newsize = out->size + size;
33
1.56k
    }
34
6.87k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.87k
    out->capacity = newsize;
36
6.87k
  }
37
139k
  if (!out->buf) {
38
4.68k
    out->size = 0;
39
4.68k
    return 0;
40
4.68k
  }
41
42
135k
  memcpy(out->buf + out->size, buffer, size);
43
135k
  out->size += size;
44
135k
  return 1;
45
139k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
181k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
181k
  size_t newsize;
26
181k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
181k
  if (out->size + size >= out->capacity) {
30
6.36k
    newsize = out->capacity << 1;
31
6.36k
    if (newsize < out->size + size) {
32
1.46k
      newsize = out->size + size;
33
1.46k
    }
34
6.36k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.36k
    out->capacity = newsize;
36
6.36k
  }
37
181k
  if (!out->buf) {
38
4.12k
    out->size = 0;
39
4.12k
    return 0;
40
4.12k
  }
41
42
177k
  memcpy(out->buf + out->size, buffer, size);
43
177k
  out->size += size;
44
177k
  return 1;
45
181k
}
46
47
#endif // YAML_WRITE_HANDLER_H_