/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 | 911k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 911k | size_t newsize; |
26 | 911k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 911k | if (out->size + size >= out->capacity) { |
30 | 17.8k | newsize = out->capacity << 1; |
31 | 17.8k | if (newsize < out->size + size) { |
32 | 3.93k | newsize = out->size + size; |
33 | 3.93k | } |
34 | 17.8k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 17.8k | out->capacity = newsize; |
36 | 17.8k | } |
37 | 911k | if (!out->buf) { |
38 | 13.4k | out->size = 0; |
39 | 13.4k | return 0; |
40 | 13.4k | } |
41 | | |
42 | 897k | memcpy(out->buf + out->size, buffer, size); |
43 | 897k | out->size += size; |
44 | 897k | return 1; |
45 | 911k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 287k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 287k | size_t newsize; | 26 | 287k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 287k | if (out->size + size >= out->capacity) { | 30 | 6.14k | newsize = out->capacity << 1; | 31 | 6.14k | if (newsize < out->size + size) { | 32 | 1.27k | newsize = out->size + size; | 33 | 1.27k | } | 34 | 6.14k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.14k | out->capacity = newsize; | 36 | 6.14k | } | 37 | 287k | if (!out->buf) { | 38 | 4.98k | out->size = 0; | 39 | 4.98k | return 0; | 40 | 4.98k | } | 41 | | | 42 | 282k | memcpy(out->buf + out->size, buffer, size); | 43 | 282k | out->size += size; | 44 | 282k | return 1; | 45 | 287k | } |
Unexecuted instantiation: libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 465k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 465k | size_t newsize; | 26 | 465k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 465k | if (out->size + size >= out->capacity) { | 30 | 5.51k | newsize = out->capacity << 1; | 31 | 5.51k | if (newsize < out->size + size) { | 32 | 1.21k | newsize = out->size + size; | 33 | 1.21k | } | 34 | 5.51k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.51k | out->capacity = newsize; | 36 | 5.51k | } | 37 | 465k | if (!out->buf) { | 38 | 4.31k | out->size = 0; | 39 | 4.31k | return 0; | 40 | 4.31k | } | 41 | | | 42 | 460k | memcpy(out->buf + out->size, buffer, size); | 43 | 460k | out->size += size; | 44 | 460k | return 1; | 45 | 465k | } |
Unexecuted instantiation: libyaml_deconstructor_fuzzer.c:yaml_write_handler Unexecuted instantiation: libyaml_dumper_fuzzer.c:yaml_write_handler libyaml_emitter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 158k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 158k | size_t newsize; | 26 | 158k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 158k | if (out->size + size >= out->capacity) { | 30 | 6.23k | newsize = out->capacity << 1; | 31 | 6.23k | if (newsize < out->size + size) { | 32 | 1.44k | newsize = out->size + size; | 33 | 1.44k | } | 34 | 6.23k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.23k | out->capacity = newsize; | 36 | 6.23k | } | 37 | 158k | if (!out->buf) { | 38 | 4.17k | out->size = 0; | 39 | 4.17k | return 0; | 40 | 4.17k | } | 41 | | | 42 | 154k | memcpy(out->buf + out->size, buffer, size); | 43 | 154k | out->size += size; | 44 | 154k | return 1; | 45 | 158k | } |
|
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |