/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 | 728k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 728k | size_t newsize; |
26 | 728k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 728k | if (out->size + size >= out->capacity) { |
30 | 25.1k | newsize = out->capacity << 1; |
31 | 25.1k | if (newsize < out->size + size) { |
32 | 6.32k | newsize = out->size + size; |
33 | 6.32k | } |
34 | 25.1k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 25.1k | out->capacity = newsize; |
36 | 25.1k | } |
37 | 728k | if (!out->buf) { |
38 | 14.3k | out->size = 0; |
39 | 14.3k | return 0; |
40 | 14.3k | } |
41 | | |
42 | 714k | memcpy(out->buf + out->size, buffer, size); |
43 | 714k | out->size += size; |
44 | 714k | return 1; |
45 | 728k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 254k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 254k | size_t newsize; | 26 | 254k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 254k | if (out->size + size >= out->capacity) { | 30 | 6.05k | newsize = out->capacity << 1; | 31 | 6.05k | if (newsize < out->size + size) { | 32 | 1.25k | newsize = out->size + size; | 33 | 1.25k | } | 34 | 6.05k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.05k | out->capacity = newsize; | 36 | 6.05k | } | 37 | 254k | if (!out->buf) { | 38 | 4.94k | out->size = 0; | 39 | 4.94k | return 0; | 40 | 4.94k | } | 41 | | | 42 | 249k | memcpy(out->buf + out->size, buffer, size); | 43 | 249k | out->size += size; | 44 | 249k | return 1; | 45 | 254k | } |
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.15k | newsize = out->capacity << 1; | 31 | 5.15k | if (newsize < out->size + size) { | 32 | 1.61k | newsize = out->size + size; | 33 | 1.61k | } | 34 | 5.15k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.15k | out->capacity = newsize; | 36 | 5.15k | } | 37 | 44.0k | if (!out->buf) { | 38 | 2.48k | out->size = 0; | 39 | 2.48k | return 0; | 40 | 2.48k | } | 41 | | | 42 | 41.5k | memcpy(out->buf + out->size, buffer, size); | 43 | 41.5k | out->size += size; | 44 | 41.5k | return 1; | 45 | 44.0k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 255k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 255k | size_t newsize; | 26 | 255k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 255k | if (out->size + size >= out->capacity) { | 30 | 5.17k | newsize = out->capacity << 1; | 31 | 5.17k | if (newsize < out->size + size) { | 32 | 1.13k | newsize = out->size + size; | 33 | 1.13k | } | 34 | 5.17k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.17k | out->capacity = newsize; | 36 | 5.17k | } | 37 | 255k | if (!out->buf) { | 38 | 4.24k | out->size = 0; | 39 | 4.24k | return 0; | 40 | 4.24k | } | 41 | | | 42 | 251k | memcpy(out->buf + out->size, buffer, size); | 43 | 251k | out->size += size; | 44 | 251k | return 1; | 45 | 255k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 33.0k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 33.0k | size_t newsize; | 26 | 33.0k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 33.0k | if (out->size + size >= out->capacity) { | 30 | 3.85k | newsize = out->capacity << 1; | 31 | 3.85k | if (newsize < out->size + size) { | 32 | 1.28k | newsize = out->size + size; | 33 | 1.28k | } | 34 | 3.85k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.85k | out->capacity = newsize; | 36 | 3.85k | } | 37 | 33.0k | if (!out->buf) { | 38 | 2.53k | out->size = 0; | 39 | 2.53k | return 0; | 40 | 2.53k | } | 41 | | | 42 | 30.5k | memcpy(out->buf + out->size, buffer, size); | 43 | 30.5k | out->size += size; | 44 | 30.5k | return 1; | 45 | 33.0k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 141k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 141k | size_t newsize; | 26 | 141k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 141k | if (out->size + size >= out->capacity) { | 30 | 4.86k | newsize = out->capacity << 1; | 31 | 4.86k | if (newsize < out->size + size) { | 32 | 1.04k | newsize = out->size + size; | 33 | 1.04k | } | 34 | 4.86k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 4.86k | out->capacity = newsize; | 36 | 4.86k | } | 37 | 141k | if (!out->buf) { | 38 | 165 | out->size = 0; | 39 | 165 | return 0; | 40 | 165 | } | 41 | | | 42 | 141k | memcpy(out->buf + out->size, buffer, size); | 43 | 141k | out->size += size; | 44 | 141k | return 1; | 45 | 141k | } |
Unexecuted instantiation: libyaml_emitter_fuzzer.c:yaml_write_handler |
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |