Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Some relatively minor changes #2

Merged
merged 3 commits into from

2 participants

@PeterScott

Hi, I saw this project on HN and thought I'd check it out. Compiling with -Wall, gave a lot of warnings, including one that was a real bug: too many arguments to sprintf(). This patch should clean things up a bit.

@udp
Owner

Looks good, cheers!

@udp udp merged commit dde2b12 into udp:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 15 deletions.
  1. +13 −15 json.c
View
28 json.c
@@ -45,19 +45,12 @@ typedef unsigned short json_uchar;
#define numeric(b) \
((b) >= '0' && (b) <= '9')
-static const unsigned char hex_table [] =
-{
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10,
- 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
-};
-
static unsigned char hex_value (json_char c)
{
- return c > 127 ? 0xFF : hex_table [c];
+ if (c >= 48 && c <= 57) return c - 48;
+ if (c >= 65 && c <= 70) return c - 55;
+ if (c >= 97 && c <= 102) return c - 87;
+ return 0xFF;
}
typedef struct
@@ -134,6 +127,7 @@ static int new_value
}
break;
+ default: break;
};
value->u.array.length = 0;
@@ -184,7 +178,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
json_state state;
int flags;
- *error = 0;
+ error[0] = '\0';
memset (&state, 0, sizeof (json_state));
memcpy (&state.settings, settings, sizeof (json_settings));
@@ -231,7 +225,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
if ((uc_b1 = hex_value (*++ i)) == 0xFF || (uc_b2 = hex_value (*++ i)) == 0xFF
|| (uc_b3 = hex_value (*++ i)) == 0xFF || (uc_b4 = hex_value (*++ i)) == 0xFF)
{
- sprintf (error, "Invalid character value (at %d:%d)", b, cur_line, e_off);
+ sprintf (error, "Invalid character value `%c` (at %d:%d)", b, cur_line, e_off);
goto e_failed;
}
@@ -312,6 +306,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
flags |= flag_seek_value | flag_need_colon;
continue;
+ default: break;
};
}
else
@@ -552,6 +547,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
flags |= flag_next | flag_reproc;
break;
+ default: break;
};
if (flags & flag_reproc)
@@ -589,6 +585,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
[parent->u.array.length] = top;
break;
+ default: break;
};
}
@@ -616,8 +613,7 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
e_failed:
- if (error)
- strcpy (error_buf, *error ? error : "Unknown error");
+ strcpy (error_buf, *error ? error : "Unknown error");
if (state.first_pass)
alloc = root;
@@ -682,6 +678,8 @@ void json_value_free (json_value * value)
free (value->u.string.ptr);
break;
+
+ default: break;
};
cur_value = value;
Something went wrong with that request. Please try again.