/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 | 857k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 857k | size_t newsize; |
26 | 857k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 857k | if (out->size + size >= out->capacity) { |
30 | 27.6k | newsize = out->capacity << 1; |
31 | 27.6k | if (newsize < out->size + size) { |
32 | 7.01k | newsize = out->size + size; |
33 | 7.01k | } |
34 | 27.6k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 27.6k | out->capacity = newsize; |
36 | 27.6k | } |
37 | 857k | if (!out->buf) { |
38 | 18.9k | out->size = 0; |
39 | 18.9k | return 0; |
40 | 18.9k | } |
41 | | |
42 | 838k | memcpy(out->buf + out->size, buffer, size); |
43 | 838k | out->size += size; |
44 | 838k | return 1; |
45 | 857k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 269k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 269k | size_t newsize; | 26 | 269k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 269k | if (out->size + size >= out->capacity) { | 30 | 6.28k | newsize = out->capacity << 1; | 31 | 6.28k | if (newsize < out->size + size) { | 32 | 1.29k | newsize = out->size + size; | 33 | 1.29k | } | 34 | 6.28k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.28k | out->capacity = newsize; | 36 | 6.28k | } | 37 | 269k | if (!out->buf) { | 38 | 4.89k | out->size = 0; | 39 | 4.89k | return 0; | 40 | 4.89k | } | 41 | | | 42 | 264k | memcpy(out->buf + out->size, buffer, size); | 43 | 264k | out->size += size; | 44 | 264k | return 1; | 45 | 269k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 44.5k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 44.5k | size_t newsize; | 26 | 44.5k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 44.5k | if (out->size + size >= out->capacity) { | 30 | 5.18k | newsize = out->capacity << 1; | 31 | 5.18k | if (newsize < out->size + size) { | 32 | 1.63k | newsize = out->size + size; | 33 | 1.63k | } | 34 | 5.18k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.18k | out->capacity = newsize; | 36 | 5.18k | } | 37 | 44.5k | if (!out->buf) { | 38 | 2.53k | out->size = 0; | 39 | 2.53k | return 0; | 40 | 2.53k | } | 41 | | | 42 | 42.0k | memcpy(out->buf + out->size, buffer, size); | 43 | 42.0k | out->size += size; | 44 | 42.0k | return 1; | 45 | 44.5k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 410k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 410k | size_t newsize; | 26 | 410k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 410k | if (out->size + size >= out->capacity) { | 30 | 5.45k | newsize = out->capacity << 1; | 31 | 5.45k | if (newsize < out->size + size) { | 32 | 1.17k | newsize = out->size + size; | 33 | 1.17k | } | 34 | 5.45k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.45k | out->capacity = newsize; | 36 | 5.45k | } | 37 | 410k | if (!out->buf) { | 38 | 4.18k | out->size = 0; | 39 | 4.18k | return 0; | 40 | 4.18k | } | 41 | | | 42 | 406k | memcpy(out->buf + out->size, buffer, size); | 43 | 406k | out->size += size; | 44 | 406k | return 1; | 45 | 410k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 34.3k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 34.3k | size_t newsize; | 26 | 34.3k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 34.3k | if (out->size + size >= out->capacity) { | 30 | 3.89k | newsize = out->capacity << 1; | 31 | 3.89k | if (newsize < out->size + size) { | 32 | 1.30k | newsize = out->size + size; | 33 | 1.30k | } | 34 | 3.89k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.89k | out->capacity = newsize; | 36 | 3.89k | } | 37 | 34.3k | if (!out->buf) { | 38 | 2.47k | out->size = 0; | 39 | 2.47k | return 0; | 40 | 2.47k | } | 41 | | | 42 | 31.8k | memcpy(out->buf + out->size, buffer, size); | 43 | 31.8k | out->size += size; | 44 | 31.8k | return 1; | 45 | 34.3k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 98.4k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 98.4k | size_t newsize; | 26 | 98.4k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 98.4k | if (out->size + size >= out->capacity) { | 30 | 6.81k | newsize = out->capacity << 1; | 31 | 6.81k | if (newsize < out->size + size) { | 32 | 1.60k | newsize = out->size + size; | 33 | 1.60k | } | 34 | 6.81k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.81k | out->capacity = newsize; | 36 | 6.81k | } | 37 | 98.4k | if (!out->buf) { | 38 | 4.91k | out->size = 0; | 39 | 4.91k | return 0; | 40 | 4.91k | } | 41 | | | 42 | 93.5k | memcpy(out->buf + out->size, buffer, size); | 43 | 93.5k | out->size += size; | 44 | 93.5k | return 1; | 45 | 98.4k | } |
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler |
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |