/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.9k | newsize = out->capacity << 1; |
31 | 27.9k | if (newsize < out->size + size) { |
32 | 7.09k | newsize = out->size + size; |
33 | 7.09k | } |
34 | 27.9k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 27.9k | out->capacity = newsize; |
36 | 27.9k | } |
37 | 857k | if (!out->buf) { |
38 | 19.0k | out->size = 0; |
39 | 19.0k | return 0; |
40 | 19.0k | } |
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 | 258k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 258k | size_t newsize; | 26 | 258k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 258k | if (out->size + size >= out->capacity) { | 30 | 6.34k | newsize = out->capacity << 1; | 31 | 6.34k | if (newsize < out->size + size) { | 32 | 1.31k | newsize = out->size + size; | 33 | 1.31k | } | 34 | 6.34k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.34k | out->capacity = newsize; | 36 | 6.34k | } | 37 | 258k | if (!out->buf) { | 38 | 4.89k | out->size = 0; | 39 | 4.89k | return 0; | 40 | 4.89k | } | 41 | | | 42 | 253k | memcpy(out->buf + out->size, buffer, size); | 43 | 253k | out->size += size; | 44 | 253k | return 1; | 45 | 258k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 43.8k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 43.8k | size_t newsize; | 26 | 43.8k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 43.8k | if (out->size + size >= out->capacity) { | 30 | 5.14k | newsize = out->capacity << 1; | 31 | 5.14k | if (newsize < out->size + size) { | 32 | 1.64k | newsize = out->size + size; | 33 | 1.64k | } | 34 | 5.14k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.14k | out->capacity = newsize; | 36 | 5.14k | } | 37 | 43.8k | if (!out->buf) { | 38 | 2.51k | out->size = 0; | 39 | 2.51k | return 0; | 40 | 2.51k | } | 41 | | | 42 | 41.3k | memcpy(out->buf + out->size, buffer, size); | 43 | 41.3k | out->size += size; | 44 | 41.3k | return 1; | 45 | 43.8k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 420k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 420k | size_t newsize; | 26 | 420k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 420k | if (out->size + size >= out->capacity) { | 30 | 5.59k | newsize = out->capacity << 1; | 31 | 5.59k | if (newsize < out->size + size) { | 32 | 1.19k | newsize = out->size + size; | 33 | 1.19k | } | 34 | 5.59k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.59k | out->capacity = newsize; | 36 | 5.59k | } | 37 | 420k | if (!out->buf) { | 38 | 4.19k | out->size = 0; | 39 | 4.19k | return 0; | 40 | 4.19k | } | 41 | | | 42 | 416k | memcpy(out->buf + out->size, buffer, size); | 43 | 416k | out->size += size; | 44 | 416k | return 1; | 45 | 420k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 32.6k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 32.6k | size_t newsize; | 26 | 32.6k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 32.6k | if (out->size + size >= out->capacity) { | 30 | 3.95k | newsize = out->capacity << 1; | 31 | 3.95k | if (newsize < out->size + size) { | 32 | 1.32k | newsize = out->size + size; | 33 | 1.32k | } | 34 | 3.95k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 3.95k | out->capacity = newsize; | 36 | 3.95k | } | 37 | 32.6k | if (!out->buf) { | 38 | 2.53k | out->size = 0; | 39 | 2.53k | return 0; | 40 | 2.53k | } | 41 | | | 42 | 30.1k | memcpy(out->buf + out->size, buffer, size); | 43 | 30.1k | out->size += size; | 44 | 30.1k | return 1; | 45 | 32.6k | } |
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.88k | newsize = out->capacity << 1; | 31 | 6.88k | if (newsize < out->size + size) { | 32 | 1.61k | newsize = out->size + size; | 33 | 1.61k | } | 34 | 6.88k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.88k | out->capacity = newsize; | 36 | 6.88k | } | 37 | 101k | if (!out->buf) { | 38 | 4.93k | out->size = 0; | 39 | 4.93k | return 0; | 40 | 4.93k | } | 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_ |