Skip to content

Commit 1c32fb5

Browse files
committed
include/parson.h: vendor/parson/parson.c: update
1 parent 57feeb5 commit 1c32fb5

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

include/parson.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
SPDX-License-Identifier: MIT
33
4-
Parson 1.5.2 (https://github.com/kgabis/parson)
4+
Parson 1.5.3 (https://github.com/kgabis/parson)
55
Copyright (c) 2012 - 2023 Krzysztof Gabis
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -36,9 +36,9 @@ extern "C"
3636

3737
#define PARSON_VERSION_MAJOR 1
3838
#define PARSON_VERSION_MINOR 5
39-
#define PARSON_VERSION_PATCH 2
39+
#define PARSON_VERSION_PATCH 3
4040

41-
#define PARSON_VERSION_STRING "1.5.2"
41+
#define PARSON_VERSION_STRING "1.5.3"
4242

4343
#include <stddef.h> /* size_t */
4444

vendor/parson/parson.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
SPDX-License-Identifier: MIT
33
4-
Parson 1.5.2 (https://github.com/kgabis/parson)
4+
Parson 1.5.3 (https://github.com/kgabis/parson)
55
Copyright (c) 2012 - 2023 Krzysztof Gabis
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -28,18 +28,19 @@
2828
#endif /* _CRT_SECURE_NO_WARNINGS */
2929
#endif /* _MSC_VER */
3030

31-
#include <parson.h>
31+
#include "parson.h"
3232

3333
#define PARSON_IMPL_VERSION_MAJOR 1
3434
#define PARSON_IMPL_VERSION_MINOR 5
35-
#define PARSON_IMPL_VERSION_PATCH 2
35+
#define PARSON_IMPL_VERSION_PATCH 3
3636

3737
#if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\
3838
|| (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\
3939
|| (PARSON_VERSION_PATCH != PARSON_IMPL_VERSION_PATCH)
4040
#error "parson version mismatch between parson.c and parson.h"
4141
#endif
4242

43+
#include <stdarg.h>
4344
#include <stdio.h>
4445
#include <stdlib.h>
4546
#include <string.h>
@@ -152,6 +153,8 @@ static char * read_file(const char *filename);
152153
static void remove_comments(char *string, const char *start_token, const char *end_token);
153154
static char * parson_strndup(const char *string, size_t n);
154155
static char * parson_strdup(const char *string);
156+
static int parson_sprintf(char * s, const char * format, ...);
157+
155158
static int hex_char_to_int(char c);
156159
static JSON_Status parse_utf16_hex(const char *string, unsigned int *result);
157160
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
250253
} else if (current_char == '\"' && !escaped) {
251254
in_string = !in_string;
252255
} 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++) {
254257
string[i] = ' ';
255258
}
256259
string = string + start_token_len;
@@ -283,6 +286,25 @@ static char * parson_strdup(const char *string) {
283286
return parson_strndup(string, strlen(string));
284287
}
285288

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+
286308
static int hex_char_to_int(char c) {
287309
if (c >= '0' && c <= '9') {
288310
return c - '0';
@@ -1243,10 +1265,9 @@ static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int le
12431265
}
12441266
if (parson_number_serialization_function) {
12451267
written = parson_number_serialization_function(num, num_buf);
1246-
} else if (parson_float_format) {
1247-
written = sprintf(num_buf, parson_float_format, num);
12481268
} 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);
12501271
}
12511272
if (written < 0) {
12521273
return -1;

0 commit comments

Comments
 (0)