/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 | 914k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 914k | size_t newsize; |
26 | 914k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 914k | if (out->size + size >= out->capacity) { |
30 | 27.3k | newsize = out->capacity << 1; |
31 | 27.3k | if (newsize < out->size + size) { |
32 | 6.97k | newsize = out->size + size; |
33 | 6.97k | } |
34 | 27.3k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 27.3k | out->capacity = newsize; |
36 | 27.3k | } |
37 | 914k | if (!out->buf) { |
38 | 19.1k | out->size = 0; |
39 | 19.1k | return 0; |
40 | 19.1k | } |
41 | | |
42 | 895k | memcpy(out->buf + out->size, buffer, size); |
43 | 895k | out->size += size; |
44 | 895k | return 1; |
45 | 914k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 249k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 249k | size_t newsize; | 26 | 249k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 249k | if (out->size + size >= out->capacity) { | 30 | 6.09k | newsize = out->capacity << 1; | 31 | 6.09k | if (newsize < out->size + size) { | 32 | 1.26k | newsize = out->size + size; | 33 | 1.26k | } | 34 | 6.09k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.09k | out->capacity = newsize; | 36 | 6.09k | } | 37 | 249k | if (!out->buf) { | 38 | 4.98k | out->size = 0; | 39 | 4.98k | return 0; | 40 | 4.98k | } | 41 | | | 42 | 244k | memcpy(out->buf + out->size, buffer, size); | 43 | 244k | out->size += size; | 44 | 244k | return 1; | 45 | 249k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 40.9k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 40.9k | size_t newsize; | 26 | 40.9k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 40.9k | if (out->size + size >= out->capacity) { | 30 | 5.07k | newsize = out->capacity << 1; | 31 | 5.07k | if (newsize < out->size + size) { | 32 | 1.61k | newsize = out->size + size; | 33 | 1.61k | } | 34 | 5.07k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.07k | out->capacity = newsize; | 36 | 5.07k | } | 37 | 40.9k | if (!out->buf) { | 38 | 2.47k | out->size = 0; | 39 | 2.47k | return 0; | 40 | 2.47k | } | 41 | | | 42 | 38.4k | memcpy(out->buf + out->size, buffer, size); | 43 | 38.4k | out->size += size; | 44 | 38.4k | return 1; | 45 | 40.9k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 438k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 438k | size_t newsize; | 26 | 438k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 438k | if (out->size + size >= out->capacity) { | 30 | 5.32k | newsize = out->capacity << 1; | 31 | 5.32k | if (newsize < out->size + size) { | 32 | 1.16k | newsize = out->size + size; | 33 | 1.16k | } | 34 | 5.32k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.32k | out->capacity = newsize; | 36 | 5.32k | } | 37 | 438k | if (!out->buf) { | 38 | 4.28k | out->size = 0; | 39 | 4.28k | return 0; | 40 | 4.28k | } | 41 | | | 42 | 434k | memcpy(out->buf + out->size, buffer, size); | 43 | 434k | out->size += size; | 44 | 434k | return 1; | 45 | 438k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 32.7k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 32.7k | size_t newsize; | 26 | 32.7k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 32.7k | if (out->size + size >= out->capacity) { | 30 | 3.87k | newsize = out->capacity << 1; | 31 | 3.87k | if (newsize < out->size + size) { | 32 | 1.29k | newsize = out->size + size; | 33 | 1.29k | } | 34 | 3.87k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.87k | out->capacity = newsize; | 36 | 3.87k | } | 37 | 32.7k | if (!out->buf) { | 38 | 2.51k | out->size = 0; | 39 | 2.51k | return 0; | 40 | 2.51k | } | 41 | | | 42 | 30.2k | memcpy(out->buf + out->size, buffer, size); | 43 | 30.2k | out->size += size; | 44 | 30.2k | return 1; | 45 | 32.7k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 152k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 152k | size_t newsize; | 26 | 152k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 152k | if (out->size + size >= out->capacity) { | 30 | 7.00k | newsize = out->capacity << 1; | 31 | 7.00k | if (newsize < out->size + size) { | 32 | 1.65k | newsize = out->size + size; | 33 | 1.65k | } | 34 | 7.00k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 7.00k | out->capacity = newsize; | 36 | 7.00k | } | 37 | 152k | if (!out->buf) { | 38 | 4.90k | out->size = 0; | 39 | 4.90k | return 0; | 40 | 4.90k | } | 41 | | | 42 | 147k | memcpy(out->buf + out->size, buffer, size); | 43 | 147k | out->size += size; | 44 | 147k | return 1; | 45 | 152k | } |
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler |
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |