Coverage Report

Created: 2026-05-30 06:46

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
965k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
965k
  size_t newsize;
26
965k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
965k
  if (out->size + size >= out->capacity) {
30
33.5k
    newsize = out->capacity << 1;
31
33.5k
    if (newsize < out->size + size) {
32
8.43k
      newsize = out->size + size;
33
8.43k
    }
34
33.5k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
33.5k
    out->capacity = newsize;
36
33.5k
  }
37
965k
  if (!out->buf) {
38
23.4k
    out->size = 0;
39
23.4k
    return 0;
40
23.4k
  }
41
42
941k
  memcpy(out->buf + out->size, buffer, size);
43
941k
  out->size += size;
44
941k
  return 1;
45
965k
}
libyaml_reformatter_alt_fuzzer.c:yaml_write_handler
Line
Count
Source
24
244k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
244k
  size_t newsize;
26
244k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
244k
  if (out->size + size >= out->capacity) {
30
6.27k
    newsize = out->capacity << 1;
31
6.27k
    if (newsize < out->size + size) {
32
1.28k
      newsize = out->size + size;
33
1.28k
    }
34
6.27k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
6.27k
    out->capacity = newsize;
36
6.27k
  }
37
244k
  if (!out->buf) {
38
4.97k
    out->size = 0;
39
4.97k
    return 0;
40
4.97k
  }
41
42
239k
  memcpy(out->buf + out->size, buffer, size);
43
239k
  out->size += size;
44
239k
  return 1;
45
244k
}
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
390k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
390k
  size_t newsize;
26
390k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
390k
  if (out->size + size >= out->capacity) {
30
5.38k
    newsize = out->capacity << 1;
31
5.38k
    if (newsize < out->size + size) {
32
1.17k
      newsize = out->size + size;
33
1.17k
    }
34
5.38k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.38k
    out->capacity = newsize;
36
5.38k
  }
37
390k
  if (!out->buf) {
38
4.38k
    out->size = 0;
39
4.38k
    return 0;
40
4.38k
  }
41
42
385k
  memcpy(out->buf + out->size, buffer, size);
43
385k
  out->size += size;
44
385k
  return 1;
45
390k
}
libyaml_deconstructor_fuzzer.c:yaml_write_handler
Line
Count
Source
24
28.7k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
28.7k
  size_t newsize;
26
28.7k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
28.7k
  if (out->size + size >= out->capacity) {
30
4.07k
    newsize = out->capacity << 1;
31
4.07k
    if (newsize < out->size + size) {
32
1.35k
      newsize = out->size + size;
33
1.35k
    }
34
4.07k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
4.07k
    out->capacity = newsize;
36
4.07k
  }
37
28.7k
  if (!out->buf) {
38
2.60k
    out->size = 0;
39
2.60k
    return 0;
40
2.60k
  }
41
42
26.1k
  memcpy(out->buf + out->size, buffer, size);
43
26.1k
  out->size += size;
44
26.1k
  return 1;
45
28.7k
}
libyaml_dumper_fuzzer.c:yaml_write_handler
Line
Count
Source
24
114k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
114k
  size_t newsize;
26
114k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
114k
  if (out->size + size >= out->capacity) {
30
7.02k
    newsize = out->capacity << 1;
31
7.02k
    if (newsize < out->size + size) {
32
1.60k
      newsize = out->size + size;
33
1.60k
    }
34
7.02k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
7.02k
    out->capacity = newsize;
36
7.02k
  }
37
114k
  if (!out->buf) {
38
4.95k
    out->size = 0;
39
4.95k
    return 0;
40
4.95k
  }
41
42
109k
  memcpy(out->buf + out->size, buffer, size);
43
109k
  out->size += size;
44
109k
  return 1;
45
114k
}
libyaml_emitter_fuzzer.c:yaml_write_handler
Line
Count
Source
24
151k
static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) {
25
151k
  size_t newsize;
26
151k
  yaml_output_buffer_t *out = (yaml_output_buffer_t *)data;
27
28
  /* Double buffer size whenever necessary */
29
151k
  if (out->size + size >= out->capacity) {
30
5.58k
    newsize = out->capacity << 1;
31
5.58k
    if (newsize < out->size + size) {
32
1.31k
      newsize = out->size + size;
33
1.31k
    }
34
5.58k
    out->buf = (unsigned char *)realloc(out->buf, newsize);
35
5.58k
    out->capacity = newsize;
36
5.58k
  }
37
151k
  if (!out->buf) {
38
3.96k
    out->size = 0;
39
3.96k
    return 0;
40
3.96k
  }
41
42
147k
  memcpy(out->buf + out->size, buffer, size);
43
147k
  out->size += size;
44
147k
  return 1;
45
151k
}
46
47
#endif // YAML_WRITE_HANDLER_H_