/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 | 801k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 801k | size_t newsize; |
26 | 801k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 801k | if (out->size + size >= out->capacity) { |
30 | 27.1k | newsize = out->capacity << 1; |
31 | 27.1k | if (newsize < out->size + size) { |
32 | 6.93k | newsize = out->size + size; |
33 | 6.93k | } |
34 | 27.1k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 27.1k | out->capacity = newsize; |
36 | 27.1k | } |
37 | 801k | if (!out->buf) { |
38 | 20.0k | out->size = 0; |
39 | 20.0k | return 0; |
40 | 20.0k | } |
41 | | |
42 | 781k | memcpy(out->buf + out->size, buffer, size); |
43 | 781k | out->size += size; |
44 | 781k | return 1; |
45 | 801k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 280k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 280k | size_t newsize; | 26 | 280k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 280k | if (out->size + size >= out->capacity) { | 30 | 6.08k | newsize = out->capacity << 1; | 31 | 6.08k | if (newsize < out->size + size) { | 32 | 1.25k | newsize = out->size + size; | 33 | 1.25k | } | 34 | 6.08k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.08k | out->capacity = newsize; | 36 | 6.08k | } | 37 | 280k | if (!out->buf) { | 38 | 5.18k | out->size = 0; | 39 | 5.18k | return 0; | 40 | 5.18k | } | 41 | | | 42 | 275k | memcpy(out->buf + out->size, buffer, size); | 43 | 275k | out->size += size; | 44 | 275k | return 1; | 45 | 280k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 44.0k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 44.0k | size_t newsize; | 26 | 44.0k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 44.0k | if (out->size + size >= out->capacity) { | 30 | 5.17k | newsize = out->capacity << 1; | 31 | 5.17k | if (newsize < out->size + size) { | 32 | 1.62k | newsize = out->size + size; | 33 | 1.62k | } | 34 | 5.17k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.17k | out->capacity = newsize; | 36 | 5.17k | } | 37 | 44.0k | if (!out->buf) { | 38 | 2.63k | out->size = 0; | 39 | 2.63k | return 0; | 40 | 2.63k | } | 41 | | | 42 | 41.4k | memcpy(out->buf + out->size, buffer, size); | 43 | 41.4k | out->size += size; | 44 | 41.4k | return 1; | 45 | 44.0k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 288k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 288k | size_t newsize; | 26 | 288k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 288k | if (out->size + size >= out->capacity) { | 30 | 5.22k | newsize = out->capacity << 1; | 31 | 5.22k | if (newsize < out->size + size) { | 32 | 1.14k | newsize = out->size + size; | 33 | 1.14k | } | 34 | 5.22k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.22k | out->capacity = newsize; | 36 | 5.22k | } | 37 | 288k | if (!out->buf) { | 38 | 4.48k | out->size = 0; | 39 | 4.48k | return 0; | 40 | 4.48k | } | 41 | | | 42 | 284k | memcpy(out->buf + out->size, buffer, size); | 43 | 284k | out->size += size; | 44 | 284k | return 1; | 45 | 288k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 34.7k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 34.7k | size_t newsize; | 26 | 34.7k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 34.7k | if (out->size + size >= out->capacity) { | 30 | 3.91k | newsize = out->capacity << 1; | 31 | 3.91k | if (newsize < out->size + size) { | 32 | 1.29k | newsize = out->size + size; | 33 | 1.29k | } | 34 | 3.91k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.91k | out->capacity = newsize; | 36 | 3.91k | } | 37 | 34.7k | if (!out->buf) { | 38 | 2.70k | out->size = 0; | 39 | 2.70k | return 0; | 40 | 2.70k | } | 41 | | | 42 | 31.9k | memcpy(out->buf + out->size, buffer, size); | 43 | 31.9k | out->size += size; | 44 | 31.9k | return 1; | 45 | 34.7k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 153k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 153k | size_t newsize; | 26 | 153k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 153k | if (out->size + size >= out->capacity) { | 30 | 6.76k | newsize = out->capacity << 1; | 31 | 6.76k | if (newsize < out->size + size) { | 32 | 1.61k | newsize = out->size + size; | 33 | 1.61k | } | 34 | 6.76k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.76k | out->capacity = newsize; | 36 | 6.76k | } | 37 | 153k | if (!out->buf) { | 38 | 5.08k | out->size = 0; | 39 | 5.08k | return 0; | 40 | 5.08k | } | 41 | | | 42 | 148k | memcpy(out->buf + out->size, buffer, size); | 43 | 148k | out->size += size; | 44 | 148k | return 1; | 45 | 153k | } |
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler |
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |