Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid warnings during build on several compilers #695

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ if (NOT DEFINED JSON_INT_T)
endif ()
endif ()

if (WIN32) # matches both msvc and cygwin
set (JSON_LONG_LONG_FORMAT "\"I64d\"")
else ()
set (JSON_LONG_LONG_FORMAT "\"lld\"")
endif ()

check_include_files (locale.h HAVE_LOCALE_H)
check_function_exists(setlocale HAVE_SETLOCALE)

Expand Down
1 change: 1 addition & 0 deletions cmake/jansson_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#define json_int_t @JSON_INT_T@
#define json_strtoint @JSON_STRTOINT@
#define JSON_INTEGER_FORMAT @JSON_INTEGER_FORMAT@
#define JSON_LONG_LONG_FORMAT @JSON_LONG_LONG_FORMAT@


/* If __atomic builtins are available they will be used to manage
Expand Down
12 changes: 10 additions & 2 deletions examples/simple_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
#include <stdio.h>
#include <stdlib.h>

#ifndef JANSSON_USING_CMAKE /* disabled if using cmake */
#ifdef _WIN32
#define JSON_LONG_LONG_FORMAT "I64d"
#else
#define JSON_LONG_LONG_FORMAT "lld"
#endif
#endif

/* forward refs */
void print_json(json_t *root);
void print_json_aux(json_t *element, int indent);
Expand Down Expand Up @@ -90,7 +98,7 @@ void print_json_object(json_t *element, int indent) {
print_json_indent(indent);
size = json_object_size(element);

printf("JSON Object of %lld pair%s:\n", (long long)size, json_plural(size));
printf("JSON Object of %" JSON_LONG_LONG_FORMAT " pair%s:\n", (long long)size, json_plural(size));
json_object_foreach(element, key, value) {
print_json_indent(indent + 2);
printf("JSON Key: \"%s\"\n", key);
Expand All @@ -103,7 +111,7 @@ void print_json_array(json_t *element, int indent) {
size_t size = json_array_size(element);
print_json_indent(indent);

printf("JSON Array of %lld element%s:\n", (long long)size, json_plural(size));
printf("JSON Array of %" JSON_LONG_LONG_FORMAT " element%s:\n", (long long)size, json_plural(size));
for (i = 0; i < size; i++) {
print_json_aux(json_array_get(element, i), indent + 2);
}
Expand Down
4 changes: 2 additions & 2 deletions src/dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,7 @@ strtod__unused(const char *s00, char **se)
U aadj2, adj, rv, rv0;
ULong y, z;
BCinfo bc;
Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL;
#ifdef USE_BF96
ULLong bhi, blo, brv, t00, t01, t02, t10, t11, terv, tg, tlo, yz;
const BF96 *p10;
Expand Down Expand Up @@ -5072,7 +5072,7 @@ dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char
#ifdef USE_BF96 /*{{*/
BF96 *p10;
ULLong dbhi, dbits, dblo, den, hb, rb, rblo, res, res0, res3, reslo, sres,
sulp, tv0, tv1, tv2, tv3, ulp, ulplo, ulpmask, ures, ureslo, zb;
sulp, tv0, tv1, tv2, tv3, ulp, ulplo, ulpmask = 0, ures, ureslo, zb;
int eulp, k1, n2, ulpadj, ulpshift;
#else /*}{*/
#ifndef Sudden_Underflow
Expand Down
2 changes: 1 addition & 1 deletion src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void jsonp_error_set_source(json_error_t *error, const char *source) {

length = strlen(source);
if (length < JSON_ERROR_SOURCE_LENGTH)
strncpy(error->source, source, length + 1);
memcpy(error->source, source, length + 1);
else {
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
memcpy(error->source, "...", 3);
Expand Down