|
1 | 1 | /* |
2 | 2 | SPDX-License-Identifier: MIT |
3 | 3 |
|
4 | | - Parson 1.5.2 (https://github.com/kgabis/parson) |
| 4 | + Parson 1.5.3 (https://github.com/kgabis/parson) |
5 | 5 | Copyright (c) 2012 - 2023 Krzysztof Gabis |
6 | 6 |
|
7 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy |
|
28 | 28 | #endif /* _CRT_SECURE_NO_WARNINGS */ |
29 | 29 | #endif /* _MSC_VER */ |
30 | 30 |
|
31 | | -#include <parson.h> |
| 31 | +#include "parson.h" |
32 | 32 |
|
33 | 33 | #define PARSON_IMPL_VERSION_MAJOR 1 |
34 | 34 | #define PARSON_IMPL_VERSION_MINOR 5 |
35 | | -#define PARSON_IMPL_VERSION_PATCH 2 |
| 35 | +#define PARSON_IMPL_VERSION_PATCH 3 |
36 | 36 |
|
37 | 37 | #if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\ |
38 | 38 | || (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\ |
39 | 39 | || (PARSON_VERSION_PATCH != PARSON_IMPL_VERSION_PATCH) |
40 | 40 | #error "parson version mismatch between parson.c and parson.h" |
41 | 41 | #endif |
42 | 42 |
|
| 43 | +#include <stdarg.h> |
43 | 44 | #include <stdio.h> |
44 | 45 | #include <stdlib.h> |
45 | 46 | #include <string.h> |
@@ -152,6 +153,8 @@ static char * read_file(const char *filename); |
152 | 153 | static void remove_comments(char *string, const char *start_token, const char *end_token); |
153 | 154 | static char * parson_strndup(const char *string, size_t n); |
154 | 155 | static char * parson_strdup(const char *string); |
| 156 | +static int parson_sprintf(char * s, const char * format, ...); |
| 157 | + |
155 | 158 | static int hex_char_to_int(char c); |
156 | 159 | static JSON_Status parse_utf16_hex(const char *string, unsigned int *result); |
157 | 160 | static int num_bytes_in_utf8_sequence(unsigned char c); |
@@ -250,7 +253,7 @@ static void remove_comments(char *string, const char *start_token, const char *e |
250 | 253 | } else if (current_char == '\"' && !escaped) { |
251 | 254 | in_string = !in_string; |
252 | 255 | } else if (!in_string && strncmp(string, start_token, start_token_len) == 0) { |
253 | | - for (i = 0; i < start_token_len; i++) { |
| 256 | + for(i = 0; i < start_token_len; i++) { |
254 | 257 | string[i] = ' '; |
255 | 258 | } |
256 | 259 | string = string + start_token_len; |
@@ -283,6 +286,25 @@ static char * parson_strdup(const char *string) { |
283 | 286 | return parson_strndup(string, strlen(string)); |
284 | 287 | } |
285 | 288 |
|
| 289 | +static int parson_sprintf(char * s, const char * format, ...) { |
| 290 | + int result; |
| 291 | + va_list args; |
| 292 | + va_start(args, format); |
| 293 | + |
| 294 | + #if defined(__APPLE__) && defined(__clang__) |
| 295 | + #pragma clang diagnostic push |
| 296 | + #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 297 | + #endif |
| 298 | + result = vsprintf(s, format, args); |
| 299 | + #if defined(__APPLE__) && defined(__clang__) |
| 300 | + #pragma clang diagnostic pop |
| 301 | + #endif |
| 302 | + |
| 303 | + va_end(args); |
| 304 | + return result; |
| 305 | + |
| 306 | +} |
| 307 | + |
286 | 308 | static int hex_char_to_int(char c) { |
287 | 309 | if (c >= '0' && c <= '9') { |
288 | 310 | return c - '0'; |
@@ -1243,10 +1265,9 @@ static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int le |
1243 | 1265 | } |
1244 | 1266 | if (parson_number_serialization_function) { |
1245 | 1267 | written = parson_number_serialization_function(num, num_buf); |
1246 | | - } else if (parson_float_format) { |
1247 | | - written = sprintf(num_buf, parson_float_format, num); |
1248 | 1268 | } else { |
1249 | | - written = sprintf(num_buf, PARSON_DEFAULT_FLOAT_FORMAT, num); |
| 1269 | + const char *float_format = parson_float_format ? parson_float_format : PARSON_DEFAULT_FLOAT_FORMAT; |
| 1270 | + written = parson_sprintf(num_buf, float_format, num); |
1250 | 1271 | } |
1251 | 1272 | if (written < 0) { |
1252 | 1273 | return -1; |
|
0 commit comments