/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 | 878k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 878k | size_t newsize; |
26 | 878k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 878k | if (out->size + size >= out->capacity) { |
30 | 27.8k | newsize = out->capacity << 1; |
31 | 27.8k | if (newsize < out->size + size) { |
32 | 7.06k | newsize = out->size + size; |
33 | 7.06k | } |
34 | 27.8k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 27.8k | out->capacity = newsize; |
36 | 27.8k | } |
37 | 878k | if (!out->buf) { |
38 | 19.0k | out->size = 0; |
39 | 19.0k | return 0; |
40 | 19.0k | } |
41 | | |
42 | 859k | memcpy(out->buf + out->size, buffer, size); |
43 | 859k | out->size += size; |
44 | 859k | return 1; |
45 | 878k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 266k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 266k | size_t newsize; | 26 | 266k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 266k | if (out->size + size >= out->capacity) { | 30 | 6.32k | newsize = out->capacity << 1; | 31 | 6.32k | if (newsize < out->size + size) { | 32 | 1.30k | newsize = out->size + size; | 33 | 1.30k | } | 34 | 6.32k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.32k | out->capacity = newsize; | 36 | 6.32k | } | 37 | 266k | if (!out->buf) { | 38 | 4.93k | out->size = 0; | 39 | 4.93k | return 0; | 40 | 4.93k | } | 41 | | | 42 | 261k | memcpy(out->buf + out->size, buffer, size); | 43 | 261k | out->size += size; | 44 | 261k | return 1; | 45 | 266k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 42.0k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 42.0k | size_t newsize; | 26 | 42.0k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 42.0k | if (out->size + size >= out->capacity) { | 30 | 5.13k | newsize = out->capacity << 1; | 31 | 5.13k | if (newsize < out->size + size) { | 32 | 1.64k | newsize = out->size + size; | 33 | 1.64k | } | 34 | 5.13k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.13k | out->capacity = newsize; | 36 | 5.13k | } | 37 | 42.0k | if (!out->buf) { | 38 | 2.50k | out->size = 0; | 39 | 2.50k | return 0; | 40 | 2.50k | } | 41 | | | 42 | 39.5k | memcpy(out->buf + out->size, buffer, size); | 43 | 39.5k | out->size += size; | 44 | 39.5k | return 1; | 45 | 42.0k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 434k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 434k | size_t newsize; | 26 | 434k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 434k | if (out->size + size >= out->capacity) { | 30 | 5.57k | newsize = out->capacity << 1; | 31 | 5.57k | if (newsize < out->size + size) { | 32 | 1.17k | newsize = out->size + size; | 33 | 1.17k | } | 34 | 5.57k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.57k | out->capacity = newsize; | 36 | 5.57k | } | 37 | 434k | if (!out->buf) { | 38 | 4.20k | out->size = 0; | 39 | 4.20k | return 0; | 40 | 4.20k | } | 41 | | | 42 | 430k | memcpy(out->buf + out->size, buffer, size); | 43 | 430k | out->size += size; | 44 | 430k | return 1; | 45 | 434k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 33.9k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 33.9k | size_t newsize; | 26 | 33.9k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 33.9k | if (out->size + size >= out->capacity) { | 30 | 3.92k | newsize = out->capacity << 1; | 31 | 3.92k | if (newsize < out->size + size) { | 32 | 1.32k | newsize = out->size + size; | 33 | 1.32k | } | 34 | 3.92k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.92k | out->capacity = newsize; | 36 | 3.92k | } | 37 | 33.9k | if (!out->buf) { | 38 | 2.51k | out->size = 0; | 39 | 2.51k | return 0; | 40 | 2.51k | } | 41 | | | 42 | 31.4k | memcpy(out->buf + out->size, buffer, size); | 43 | 31.4k | out->size += size; | 44 | 31.4k | return 1; | 45 | 33.9k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 101k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 101k | size_t newsize; | 26 | 101k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 101k | if (out->size + size >= out->capacity) { | 30 | 6.87k | newsize = out->capacity << 1; | 31 | 6.87k | if (newsize < out->size + size) { | 32 | 1.61k | newsize = out->size + size; | 33 | 1.61k | } | 34 | 6.87k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.87k | out->capacity = newsize; | 36 | 6.87k | } | 37 | 101k | if (!out->buf) { | 38 | 4.91k | out->size = 0; | 39 | 4.91k | return 0; | 40 | 4.91k | } | 41 | | | 42 | 96.4k | memcpy(out->buf + out->size, buffer, size); | 43 | 96.4k | out->size += size; | 44 | 96.4k | return 1; | 45 | 101k | } |
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler |
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |