Coverage Report

Created: 2026-03-12 06:57

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
805k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
805k
  size_t newsize;
26
805k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
805k
  if (out->size + size >= out->capacity) {
30
30.1k
    newsize = out->capacity << 1;
31
30.1k
    if (newsize < out->size + size) {
32
7.83k
      newsize = out->size + size;
33
7.83k
    }
34
30.1k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
30.1k
    out->capacity = newsize;
36
30.1k
  }
37
805k
  if (!out->buf) {
38
20.3k
    out->size = 0;
39
20.3k
    return 0;
40
20.3k
  }
41
42
784k
  memcpy(out->buf + out->size, buffer, size);
43
784k
  out->size += size;
44
784k
  return 1;
45
805k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
248k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
248k
  size_t newsize;
26
248k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
248k
  if (out->size + size >= out->capacity) {
30
6.37k
    newsize = out->capacity << 1;
31
6.37k
    if (newsize < out->size + size) {
32
1.31k
      newsize = out->size + size;
33
1.31k
    }
34
6.37k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.37k
    out->capacity = newsize;
36
6.37k
  }
37
248k
  if (!out->buf) {
38
4.96k
    out->size = 0;
39
4.96k
    return 0;
40
4.96k
  }
41
42
243k
  memcpy(out->buf + out->size, buffer, size);
43
243k
  out->size += size;
44
243k
  return 1;
45
248k
}
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
400k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
400k
  size_t newsize;
26
400k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
400k
  if (out->size + size >= out->capacity) {
30
5.63k
    newsize = out->capacity << 1;
31
5.63k
    if (newsize < out->size + size) {
32
1.21k
      newsize = out->size + size;
33
1.21k
    }
34
5.63k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.63k
    out->capacity = newsize;
36
5.63k
  }
37
400k
  if (!out->buf) {
38
4.22k
    out->size = 0;
39
4.22k
    return 0;
40
4.22k
  }
41
42
395k
  memcpy(out->buf + out->size, buffer, size);
43
395k
  out->size += size;
44
395k
  return 1;
45
400k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
29.8k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
29.8k
  size_t newsize;
26
29.8k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
29.8k
  if (out->size + size >= out->capacity) {
30
4.04k
    newsize = out->capacity << 1;
31
4.04k
    if (newsize < out->size + size) {
32
1.34k
      newsize = out->size + size;
33
1.34k
    }
34
4.04k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.04k
    out->capacity = newsize;
36
4.04k
  }
37
29.8k
  if (!out->buf) {
38
2.56k
    out->size = 0;
39
2.56k
    return 0;
40
2.56k
  }
41
42
27.2k
  memcpy(out->buf + out->size, buffer, size);
43
27.2k
  out->size += size;
44
27.2k
  return 1;
45
29.8k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
79.6k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
79.6k
  size_t newsize;
26
79.6k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
79.6k
  if (out->size + size >= out->capacity) {
30
7.03k
    newsize = out->capacity << 1;
31
7.03k
    if (newsize < out->size + size) {
32
1.66k
      newsize = out->size + size;
33
1.66k
    }
34
7.03k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.03k
    out->capacity = newsize;
36
7.03k
  }
37
79.6k
  if (!out->buf) {
38
4.99k
    out->size = 0;
39
4.99k
    return 0;
40
4.99k
  }
41
42
74.6k
  memcpy(out->buf + out->size, buffer, size);
43
74.6k
  out->size += size;
44
74.6k
  return 1;
45
79.6k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
10.1k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
10.1k
  size_t newsize;
26
10.1k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
10.1k
  if (out->size + size >= out->capacity) {
30
1.86k
    newsize = out->capacity << 1;
31
1.86k
    if (newsize < out->size + size) {
32
622
      newsize = out->size + size;
33
622
    }
34
1.86k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
1.86k
    out->capacity = newsize;
36
1.86k
  }
37
10.1k
  if (!out->buf) {
38
1.02k
    out->size = 0;
39
1.02k
    return 0;
40
1.02k
  }
41
42
9.11k
  memcpy(out->buf + out->size, buffer, size);
43
9.11k
  out->size += size;
44
9.11k
  return 1;
45
10.1k
}
46
47
#endif // YAML_WRITE_HANDLER_H_