Coverage Report

Created: 2026-12-01 06:11

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.19M
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
1.19M
  size_t newsize;
26
1.19M
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
1.19M
  if (out->size + size >= out->capacity) {
30
35.0k
    newsize = out->capacity << 1;
31
35.0k
    if (newsize < out->size + size) {
32
8.61k
      newsize = out->size + size;
33
8.61k
    }
34
35.0k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
35.0k
    out->capacity = newsize;
36
35.0k
  }
37
1.19M
  if (!out->buf) {
38
23.5k
    out->size = 0;
39
23.5k
    return 0;
40
23.5k
  }
41
42
1.17M
  memcpy(out->buf + out->size, buffer, size);
43
1.17M
  out->size += size;
44
1.17M
  return 1;
45
1.19M
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
317k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
317k
  size_t newsize;
26
317k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
317k
  if (out->size + size >= out->capacity) {
30
6.29k
    newsize = out->capacity << 1;
31
6.29k
    if (newsize < out->size + size) {
32
1.28k
      newsize = out->size + size;
33
1.28k
    }
34
6.29k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.29k
    out->capacity = newsize;
36
6.29k
  }
37
317k
  if (!out->buf) {
38
4.98k
    out->size = 0;
39
4.98k
    return 0;
40
4.98k
  }
41
42
312k
  memcpy(out->buf + out->size, buffer, size);
43
312k
  out->size += size;
44
312k
  return 1;
45
317k
}
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
38.5k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
38.5k
  size_t newsize;
26
38.5k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
38.5k
  if (out->size + size >= out->capacity) {
30
5.15k
    newsize = out->capacity << 1;
31
5.15k
    if (newsize < out->size + size) {
32
1.66k
      newsize = out->size + size;
33
1.66k
    }
34
5.15k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.15k
    out->capacity = newsize;
36
5.15k
  }
37
38.5k
  if (!out->buf) {
38
2.60k
    out->size = 0;
39
2.60k
    return 0;
40
2.60k
  }
41
42
35.9k
  memcpy(out->buf + out->size, buffer, size);
43
35.9k
  out->size += size;
44
35.9k
  return 1;
45
38.5k
}
libyaml_reformatter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
476k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
476k
  size_t newsize;
26
476k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
476k
  if (out->size + size >= out->capacity) {
30
5.58k
    newsize = out->capacity << 1;
31
5.58k
    if (newsize < out->size + size) {
32
1.23k
      newsize = out->size + size;
33
1.23k
    }
34
5.58k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.58k
    out->capacity = newsize;
36
5.58k
  }
37
476k
  if (!out->buf) {
38
4.34k
    out->size = 0;
39
4.34k
    return 0;
40
4.34k
  }
41
42
471k
  memcpy(out->buf + out->size, buffer, size);
43
471k
  out->size += size;
44
471k
  return 1;
45
476k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
36.5k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
36.5k
  size_t newsize;
26
36.5k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
36.5k
  if (out->size + size >= out->capacity) {
30
4.10k
    newsize = out->capacity << 1;
31
4.10k
    if (newsize < out->size + size) {
32
1.31k
      newsize = out->size + size;
33
1.31k
    }
34
4.10k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.10k
    out->capacity = newsize;
36
4.10k
  }
37
36.5k
  if (!out->buf) {
38
2.57k
    out->size = 0;
39
2.57k
    return 0;
40
2.57k
  }
41
42
33.9k
  memcpy(out->buf + out->size, buffer, size);
43
33.9k
  out->size += size;
44
33.9k
  return 1;
45
36.5k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
152k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
152k
  size_t newsize;
26
152k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
152k
  if (out->size + size >= out->capacity) {
30
7.44k
    newsize = out->capacity << 1;
31
7.44k
    if (newsize < out->size + size) {
32
1.64k
      newsize = out->size + size;
33
1.64k
    }
34
7.44k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.44k
    out->capacity = newsize;
36
7.44k
  }
37
152k
  if (!out->buf) {
38
4.91k
    out->size = 0;
39
4.91k
    return 0;
40
4.91k
  }
41
42
147k
  memcpy(out->buf + out->size, buffer, size);
43
147k
  out->size += size;
44
147k
  return 1;
45
152k
}
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.49k
    newsize = out->capacity << 1;
31
6.49k
    if (newsize < out->size + size) {
32
1.47k
      newsize = out->size + size;
33
1.47k
    }
34
6.49k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.49k
    out->capacity = newsize;
36
6.49k
  }
37
177k
  if (!out->buf) {
38
4.11k
    out->size = 0;
39
4.11k
    return 0;
40
4.11k
  }
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_