/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 | 388k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 388k | size_t newsize; |
26 | 388k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 388k | if (out->size + size >= out->capacity) { |
30 | 22.7k | newsize = out->capacity << 1; |
31 | 22.7k | if (newsize < out->size + size) { |
32 | 6.24k | newsize = out->size + size; |
33 | 6.24k | } |
34 | 22.7k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 22.7k | out->capacity = newsize; |
36 | 22.7k | } |
37 | 388k | if (!out->buf) { |
38 | 18.8k | out->size = 0; |
39 | 18.8k | return 0; |
40 | 18.8k | } |
41 | | |
42 | 369k | memcpy(out->buf + out->size, buffer, size); |
43 | 369k | out->size += size; |
44 | 369k | return 1; |
45 | 388k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 188k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 188k | size_t newsize; | 26 | 188k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 188k | if (out->size + size >= out->capacity) { | 30 | 5.04k | newsize = out->capacity << 1; | 31 | 5.04k | if (newsize < out->size + size) { | 32 | 1.10k | newsize = out->size + size; | 33 | 1.10k | } | 34 | 5.04k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.04k | out->capacity = newsize; | 36 | 5.04k | } | 37 | 188k | if (!out->buf) { | 38 | 4.94k | out->size = 0; | 39 | 4.94k | return 0; | 40 | 4.94k | } | 41 | | | 42 | 183k | memcpy(out->buf + out->size, buffer, size); | 43 | 183k | out->size += size; | 44 | 183k | return 1; | 45 | 188k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 40.7k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 40.7k | size_t newsize; | 26 | 40.7k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 40.7k | if (out->size + size >= out->capacity) { | 30 | 5.42k | newsize = out->capacity << 1; | 31 | 5.42k | if (newsize < out->size + size) { | 32 | 1.39k | newsize = out->size + size; | 33 | 1.39k | } | 34 | 5.42k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.42k | out->capacity = newsize; | 36 | 5.42k | } | 37 | 40.7k | if (!out->buf) { | 38 | 4.73k | out->size = 0; | 39 | 4.73k | return 0; | 40 | 4.73k | } | 41 | | | 42 | 35.9k | memcpy(out->buf + out->size, buffer, size); | 43 | 35.9k | out->size += size; | 44 | 35.9k | return 1; | 45 | 40.7k | } |
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 91.6k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 91.6k | size_t newsize; | 26 | 91.6k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 91.6k | if (out->size + size >= out->capacity) { | 30 | 4.17k | newsize = out->capacity << 1; | 31 | 4.17k | if (newsize < out->size + size) { | 32 | 996 | newsize = out->size + size; | 33 | 996 | } | 34 | 4.17k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 4.17k | out->capacity = newsize; | 36 | 4.17k | } | 37 | 91.6k | if (!out->buf) { | 38 | 4.19k | out->size = 0; | 39 | 4.19k | return 0; | 40 | 4.19k | } | 41 | | | 42 | 87.4k | memcpy(out->buf + out->size, buffer, size); | 43 | 87.4k | out->size += size; | 44 | 87.4k | return 1; | 45 | 91.6k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 38.2k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 38.2k | size_t newsize; | 26 | 38.2k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 38.2k | if (out->size + size >= out->capacity) { | 30 | 4.60k | newsize = out->capacity << 1; | 31 | 4.60k | if (newsize < out->size + size) { | 32 | 1.57k | newsize = out->size + size; | 33 | 1.57k | } | 34 | 4.60k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 4.60k | out->capacity = newsize; | 36 | 4.60k | } | 37 | 38.2k | if (!out->buf) { | 38 | 2.51k | out->size = 0; | 39 | 2.51k | return 0; | 40 | 2.51k | } | 41 | | | 42 | 35.7k | memcpy(out->buf + out->size, buffer, size); | 43 | 35.7k | out->size += size; | 44 | 35.7k | return 1; | 45 | 38.2k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 29.9k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 29.9k | size_t newsize; | 26 | 29.9k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 29.9k | if (out->size + size >= out->capacity) { | 30 | 3.52k | newsize = out->capacity << 1; | 31 | 3.52k | if (newsize < out->size + size) { | 32 | 1.17k | newsize = out->size + size; | 33 | 1.17k | } | 34 | 3.52k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.52k | out->capacity = newsize; | 36 | 3.52k | } | 37 | 29.9k | if (!out->buf) { | 38 | 2.51k | out->size = 0; | 39 | 2.51k | return 0; | 40 | 2.51k | } | 41 | | | 42 | 27.4k | memcpy(out->buf + out->size, buffer, size); | 43 | 27.4k | out->size += size; | 44 | 27.4k | return 1; | 45 | 29.9k | } |
|
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |