Coverage Report

Created: 2026-03-15 06:40

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
824k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
824k
  size_t newsize;
26
824k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
824k
  if (out->size + size >= out->capacity) {
30
30.3k
    newsize = out->capacity << 1;
31
30.3k
    if (newsize < out->size + size) {
32
7.90k
      newsize = out->size + size;
33
7.90k
    }
34
30.3k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
30.3k
    out->capacity = newsize;
36
30.3k
  }
37
824k
  if (!out->buf) {
38
20.4k
    out->size = 0;
39
20.4k
    return 0;
40
20.4k
  }
41
42
804k
  memcpy(out->buf + out->size, buffer, size);
43
804k
  out->size += size;
44
804k
  return 1;
45
824k
}
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.36k
    newsize = out->capacity << 1;
31
6.36k
    if (newsize < out->size + size) {
32
1.30k
      newsize = out->size + size;
33
1.30k
    }
34
6.36k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.36k
    out->capacity = newsize;
36
6.36k
  }
37
248k
  if (!out->buf) {
38
4.98k
    out->size = 0;
39
4.98k
    return 0;
40
4.98k
  }
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
401k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
401k
  size_t newsize;
26
401k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
401k
  if (out->size + size >= out->capacity) {
30
5.65k
    newsize = out->capacity << 1;
31
5.65k
    if (newsize < out->size + size) {
32
1.21k
      newsize = out->size + size;
33
1.21k
    }
34
5.65k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.65k
    out->capacity = newsize;
36
5.65k
  }
37
401k
  if (!out->buf) {
38
4.20k
    out->size = 0;
39
4.20k
    return 0;
40
4.20k
  }
41
42
396k
  memcpy(out->buf + out->size, buffer, size);
43
396k
  out->size += size;
44
396k
  return 1;
45
401k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
30.0k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
30.0k
  size_t newsize;
26
30.0k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
30.0k
  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
30.0k
  if (!out->buf) {
38
2.53k
    out->size = 0;
39
2.53k
    return 0;
40
2.53k
  }
41
42
27.5k
  memcpy(out->buf + out->size, buffer, size);
43
27.5k
  out->size += size;
44
27.5k
  return 1;
45
30.0k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
97.7k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
97.7k
  size_t newsize;
26
97.7k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
97.7k
  if (out->size + size >= out->capacity) {
30
7.05k
    newsize = out->capacity << 1;
31
7.05k
    if (newsize < out->size + size) {
32
1.66k
      newsize = out->size + size;
33
1.66k
    }
34
7.05k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.05k
    out->capacity = newsize;
36
7.05k
  }
37
97.7k
  if (!out->buf) {
38
4.95k
    out->size = 0;
39
4.95k
    return 0;
40
4.95k
  }
41
42
92.8k
  memcpy(out->buf + out->size, buffer, size);
43
92.8k
  out->size += size;
44
92.8k
  return 1;
45
97.7k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
10.7k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
10.7k
  size_t newsize;
26
10.7k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
10.7k
  if (out->size + size >= out->capacity) {
30
2.02k
    newsize = out->capacity << 1;
31
2.02k
    if (newsize < out->size + size) {
32
684
      newsize = out->size + size;
33
684
    }
34
2.02k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
2.02k
    out->capacity = newsize;
36
2.02k
  }
37
10.7k
  if (!out->buf) {
38
1.13k
    out->size = 0;
39
1.13k
    return 0;
40
1.13k
  }
41
42
9.57k
  memcpy(out->buf + out->size, buffer, size);
43
9.57k
  out->size += size;
44
9.57k
  return 1;
45
10.7k
}
46
47
#endif // YAML_WRITE_HANDLER_H_