Skip to content

Commit 8e7c787

Browse files
author
James Alastair McLaughlin
authored
Merge pull request #10 from marcelmeulemans/master
A few small fixes for strict compiler settings.
2 parents 19c739f + 02d099c commit 8e7c787

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

json-builder.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
#include <string.h>
3434
#include <assert.h>
3535
#include <stdio.h>
36-
#include <math.h>
3736

3837
#ifdef _MSC_VER
3938
#define snprintf _snprintf
4039
#endif
4140

42-
const static json_serialize_opts default_opts =
41+
static double floor(double d) {
42+
return d - ((int)d % 1);
43+
}
44+
45+
static const json_serialize_opts default_opts =
4346
{
4447
json_serialize_mode_single_line,
4548
0,
@@ -99,7 +102,7 @@ const int f_spaces_after_commas = (1 << 1);
99102
const int f_spaces_after_colons = (1 << 2);
100103
const int f_tabs = (1 << 3);
101104

102-
int get_serialize_flags (json_serialize_opts opts)
105+
static int get_serialize_flags (json_serialize_opts opts)
103106
{
104107
int flags = 0;
105108

@@ -357,7 +360,7 @@ json_value * json_boolean_new (int b)
357360
return value;
358361
}
359362

360-
json_value * json_null_new ()
363+
json_value * json_null_new (void)
361364
{
362365
json_value * value = (json_value *) calloc (1, sizeof (json_builder_value));
363366

@@ -885,7 +888,7 @@ void json_serialize_ex (json_char * buf, json_value * value, json_serialize_opts
885888
{
886889
*dot = '.';
887890
}
888-
else if (!strchr (ptr, '.'))
891+
else if (!strchr (ptr, '.') && !strchr (ptr, 'e'))
889892
{
890893
*buf ++ = '.';
891894
*buf ++ = '0';

json-builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ json_value * json_string_new_nocopy (unsigned int length, json_char *);
107107
json_value * json_integer_new (json_int_t);
108108
json_value * json_double_new (double);
109109
json_value * json_boolean_new (int);
110-
json_value * json_null_new ();
110+
json_value * json_null_new (void);
111111

112112

113113
/*** Serializing

test/main.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,17 @@ void test_buf (char * buffer, size_t size, int * num_failed)
127127
char * buf = (char *) malloc (measured);
128128
json_serialize (buf, value);
129129

130-
printf ("serialized len: %d\n", (int) strlen (buf) + 1);
130+
size_t serialized = (int) strlen (buf) + 1;
131+
printf ("serialized len: %d\n", serialized);
131132

132133
printf ("serialized:\n%s\n", buf);
133134

134-
if (! (value2 = json_parse_ex (&settings, buf, strlen(buf), error)))
135+
if (serialized > measured)
136+
{
137+
printf ("Serialized more than measured\n");
138+
++ *num_failed;
139+
}
140+
else if (! (value2 = json_parse_ex (&settings, buf, strlen(buf), error)))
135141
{
136142
printf ("Failed to re-parse: %s\n", error);
137143
++ *num_failed;

0 commit comments

Comments
 (0)