Skip to content

Instantly share code, notes, and snippets.

@tibbon
Forked from stevestreza/unsignedLong.patch
Created June 16, 2009 15:58
Show Gist options
  • Save tibbon/130753 to your computer and use it in GitHub Desktop.
Save tibbon/130753 to your computer and use it in GitHub Desktop.
diff --git a/src/yajl_parser.c b/src/yajl_parser.c
index 398873c..96add32 100644
--- a/src/yajl_parser.c
+++ b/src/yajl_parser.c
@@ -226,11 +226,11 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
_CC_CHK(hand->callbacks->yajl_number(
hand->ctx,(const char *) buf, bufLen));
} else if (hand->callbacks->yajl_integer) {
- long int i = 0;
+ unsigned long i = 0;
yajl_buf_clear(hand->decodeBuf);
yajl_buf_append(hand->decodeBuf, buf, bufLen);
buf = yajl_buf_data(hand->decodeBuf);
- i = strtol((const char *) buf, NULL, 10);
- if ((i == LONG_MIN || i == LONG_MAX) &&
+ i = strtoul((const char *) buf, NULL, 10);
+ if ((i == ULONG_MIN || i == ULONG_MAX) &&
errno == ERANGE)
{
diff --git a/src/yajl_parser.c b/src/yajl_parser.c
index 398873c..47041c9 100644
--- a/src/yajl_parser.c
+++ b/src/yajl_parser.c
@@ -226,12 +226,16 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
_CC_CHK(hand->callbacks->yajl_number(
hand->ctx,(const char *) buf, bufLen));
} else if (hand->callbacks->yajl_integer) {
- long int i = 0;
+ unsigned long long i = 0;
yajl_buf_clear(hand->decodeBuf);
yajl_buf_append(hand->decodeBuf, buf, bufLen);
buf = yajl_buf_data(hand->decodeBuf);
- i = strtol((const char *) buf, NULL, 10);
- if ((i == LONG_MIN || i == LONG_MAX) &&
+ i = strtoull((const char *) buf, NULL, 10);
+#ifndef ULONG_LONG_MAX
+#define ULONG_LONG_MAX (0ULL - 1ULL)
+#endif
+
+ if ((i == ULONG_LONG_MAX) &&
errno == ERANGE)
{
yajl_state_set(hand, yajl_state_parse_error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment