Coverage Report

Created: 2026-10-17 06:26

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.16M
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
1.16M
  size_t newsize;
26
1.16M
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
1.16M
  if (out->size + size >= out->capacity) {
30
33.8k
    newsize = out->capacity << 1;
31
33.8k
    if (newsize < out->size + size) {
32
8.35k
      newsize = out->size + size;
33
8.35k
    }
34
33.8k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
33.8k
    out->capacity = newsize;
36
33.8k
  }
37
1.16M
  if (!out->buf) {
38
22.9k
    out->size = 0;
39
22.9k
    return 0;
40
22.9k
  }
41
42
1.14M
  memcpy(out->buf + out->size, buffer, size);
43
1.14M
  out->size += size;
44
1.14M
  return 1;
45
1.16M
}
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.18k
    newsize = out->capacity << 1;
31
6.18k
    if (newsize < out->size + size) {
32
1.26k
      newsize = out->size + size;
33
1.26k
    }
34
6.18k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.18k
    out->capacity = newsize;
36
6.18k
  }
37
311k
  if (!out->buf) {
38
4.95k
    out->size = 0;
39
4.95k
    return 0;
40
4.95k
  }
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
35.8k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
35.8k
  size_t newsize;
26
35.8k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
35.8k
  if (out->size + size >= out->capacity) {
30
4.88k
    newsize = out->capacity << 1;
31
4.88k
    if (newsize < out->size + size) {
32
1.58k
      newsize = out->size + size;
33
1.58k
    }
34
4.88k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.88k
    out->capacity = newsize;
36
4.88k
  }
37
35.8k
  if (!out->buf) {
38
2.41k
    out->size = 0;
39
2.41k
    return 0;
40
2.41k
  }
41
42
33.4k
  memcpy(out->buf + out->size, buffer, size);
43
33.4k
  out->size += size;
44
33.4k
  return 1;
45
35.8k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
467k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
467k
  size_t newsize;
26
467k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
467k
  if (out->size + size >= out->capacity) {
30
5.51k
    newsize = out->capacity << 1;
31
5.51k
    if (newsize < out->size + size) {
32
1.21k
      newsize = out->size + size;
33
1.21k
    }
34
5.51k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.51k
    out->capacity = newsize;
36
5.51k
  }
37
467k
  if (!out->buf) {
38
4.29k
    out->size = 0;
39
4.29k
    return 0;
40
4.29k
  }
41
42
462k
  memcpy(out->buf + out->size, buffer, size);
43
462k
  out->size += size;
44
462k
  return 1;
45
467k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
30.6k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
30.6k
  size_t newsize;
26
30.6k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
30.6k
  if (out->size + size >= out->capacity) {
30
3.93k
    newsize = out->capacity << 1;
31
3.93k
    if (newsize < out->size + size) {
32
1.25k
      newsize = out->size + size;
33
1.25k
    }
34
3.93k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
3.93k
    out->capacity = newsize;
36
3.93k
  }
37
30.6k
  if (!out->buf) {
38
2.47k
    out->size = 0;
39
2.47k
    return 0;
40
2.47k
  }
41
42
28.1k
  memcpy(out->buf + out->size, buffer, size);
43
28.1k
  out->size += size;
44
28.1k
  return 1;
45
30.6k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
142k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
142k
  size_t newsize;
26
142k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
142k
  if (out->size + size >= out->capacity) {
30
6.98k
    newsize = out->capacity << 1;
31
6.98k
    if (newsize < out->size + size) {
32
1.57k
      newsize = out->size + size;
33
1.57k
    }
34
6.98k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.98k
    out->capacity = newsize;
36
6.98k
  }
37
142k
  if (!out->buf) {
38
4.69k
    out->size = 0;
39
4.69k
    return 0;
40
4.69k
  }
41
42
138k
  memcpy(out->buf + out->size, buffer, size);
43
138k
  out->size += size;
44
138k
  return 1;
45
142k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
177k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
177k
  size_t newsize;
26
177k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
177k
  if (out->size + size >= out->capacity) {
30
6.34k
    newsize = out->capacity << 1;
31
6.34k
    if (newsize < out->size + size) {
32
1.46k
      newsize = out->size + size;
33
1.46k
    }
34
6.34k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.34k
    out->capacity = newsize;
36
6.34k
  }
37
177k
  if (!out->buf) {
38
4.07k
    out->size = 0;
39
4.07k
    return 0;
40
4.07k
  }
41
42
173k
  memcpy(out->buf + out->size, buffer, size);
43
173k
  out->size += size;
44
173k
  return 1;
45
177k
}
46
47
#endif // YAML_WRITE_HANDLER_H_