Browse files

Fixed all compilers warnings on Level4 MSVC++

  • Loading branch information...
1 parent d5615fe commit a1747b95c65941573aaf9bba3ccb14a75bbea742 @jskorpan jskorpan committed Nov 13, 2012
Showing with 36 additions and 53 deletions.
  1. +19 −29 lib/ultrajsondec.c
  2. +17 −24 lib/ultrajsonenc.c
View
48 lib/ultrajsondec.c
@@ -90,19 +90,19 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
double expValue;
char *offset = ds->start;
- JSUINT64 overflowLimit = LLONG_MAX;
+ JSUINT64 overflowLimit = (JSUINT64) LLONG_MAX;
if (*(offset) == '-')
{
offset ++;
intNeg = -1;
- overflowLimit = LLONG_MIN;
+ overflowLimit = (JSUINT64) LLONG_MIN;
}
// Scan integer part
intValue = 0;
- while (1)
+ for (;;)
{
chr = (int) (unsigned char) *(offset);
@@ -125,10 +125,10 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
#else
intValue = intValue * 10ULL + (JSLONG) (chr - 48);
- if (intValue > overflowLimit)
- {
- return SetError(ds, -1, overflowLimit == LLONG_MAX ? "Value is too big" : "Value is too small");
- }
+ if (intValue > overflowLimit)
+ {
+ return SetError(ds, -1, intNeg == -1 ? "Value is too small" : "Value is too big");
+ }
#endif
offset ++;
@@ -188,7 +188,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
// Scan fraction part
frcValue = 0.0;
- while (1)
+ for (;;)
{
chr = (int) (unsigned char) *(offset);
@@ -252,7 +252,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
expValue = 0.0;
- while (1)
+ for (;;)
{
chr = (int) (unsigned char) *(offset);
@@ -362,7 +362,7 @@ FASTCALL_ATTR void FASTCALL_MSVC SkipWhitespace(struct DecoderState *ds)
{
char *offset = ds->start;
- while (1)
+ for (;;)
{
switch (*offset)
{
@@ -424,7 +424,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_string ( struct DecoderState *ds)
ds->lastType = JT_INVALID;
ds->start ++;
- if ( (ds->end - ds->start) > escLen)
+ if ( (size_t) (ds->end - ds->start) > escLen)
{
size_t newSize = (ds->end - ds->start);
@@ -452,9 +452,9 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_string ( struct DecoderState *ds)
}
escOffset = ds->escStart;
- inputOffset = ds->start;
+ inputOffset = (JSUINT8 *) ds->start;
- while(1)
+ for (;;)
{
switch (g_decoderLookup[(JSUINT8)(*inputOffset)])
{
@@ -631,8 +631,8 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_string ( struct DecoderState *ds)
if (ucs >= 0x10000)
{
ucs -= 0x10000;
- *(escOffset++) = (ucs >> 10) + 0xd800;
- *(escOffset++) = (ucs & 0x3ff) + 0xdc00;
+ *(escOffset++) = (wchar_t) (ucs >> 10) + 0xd800;
+ *(escOffset++) = (wchar_t) (ucs & 0x3ff) + 0xdc00;
}
else
{
@@ -657,7 +657,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_array( struct DecoderState *ds)
ds->start ++;
- while (1)//(*ds->start) != '\0')
+ for (;;)
{
SkipWhitespace(ds);
@@ -680,11 +680,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_array( struct DecoderState *ds)
default:
ds->dec->releaseObject(newObj);
return SetError(ds, -1, "Unexpected character in found when decoding array value");
- }
-
-
- ds->dec->releaseObject(newObj);
- return NULL;
+ }
}
ds->dec->arrayAddItem (newObj, itemValue);
@@ -706,9 +702,6 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_array( struct DecoderState *ds)
len ++;
}
-
- ds->dec->releaseObject(newObj);
- return SetError(ds, -1, "Unmatched ']' when decoding 'array'");
}
@@ -721,7 +714,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_object( struct DecoderState *ds)
ds->start ++;
- while (1)
+ for (;;)
{
SkipWhitespace(ds);
@@ -784,14 +777,11 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_object( struct DecoderState *ds)
return SetError(ds, -1, "Unexpected character in found when decoding object value");
}
}
-
- ds->dec->releaseObject(newObj);
- return SetError(ds, -1, "Unmatched '}' when decoding object");
}
FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_any(struct DecoderState *ds)
{
- while (1)
+ for (;;)
{
switch (*ds->start)
{
View
41 lib/ultrajsonenc.c
@@ -51,7 +51,6 @@ static const double g_pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000
static const char g_hexChars[] = "0123456789abcdef";
static const char g_escapeChars[] = "0123456789\\b\\t\\n\\f\\r\\\"\\\\\\/";
-
/*
FIXME: While this is fine dandy and working it's a magic value mess which probably only the author understands.
Needs a cleanup and more documentation */
@@ -132,11 +131,11 @@ FASTCALL_ATTR INLINE_PREFIX void FASTCALL_MSVC Buffer_AppendShortHexUnchecked (c
*(outputOffset++) = g_hexChars[(value & 0x000f) >> 0];
}
-int Buffer_EscapeStringUnvalidated (JSOBJ obj, JSONObjectEncoder *enc, const char *io, const char *end)
+int Buffer_EscapeStringUnvalidated (JSONObjectEncoder *enc, const char *io, const char *end)
{
char *of = (char *) enc->offset;
- while (1)
+ for (;;)
{
switch (*io)
{
@@ -205,25 +204,14 @@ int Buffer_EscapeStringUnvalidated (JSOBJ obj, JSONObjectEncoder *enc, const cha
io++;
}
-
- return FALSE;
}
-
-/*
-FIXME:
-This code only works with Little and Big Endian
-
-FIXME: The JSON spec says escape "/" but non of the others do and we don't
-want to be left alone doing it so we don't :)
-
-*/
int Buffer_EscapeStringValidated (JSOBJ obj, JSONObjectEncoder *enc, const char *io, const char *end)
{
JSUTF32 ucs;
char *of = (char *) enc->offset;
- while (1)
+ for (;;)
{
//JSUINT8 chr = (unsigned char) *io;
@@ -383,6 +371,9 @@ int Buffer_EscapeStringValidated (JSOBJ obj, JSONObjectEncoder *enc, const char
*(of++) = *( (char *) (g_escapeChars + utflen + 1));
io ++;
continue;
+
+ // This can never happen, it's here to make L4 VC++ happy
+ default: ucs = 0; break;
}
/*
@@ -392,28 +383,26 @@ int Buffer_EscapeStringValidated (JSOBJ obj, JSONObjectEncoder *enc, const char
ucs -= 0x10000;
*(of++) = '\\';
*(of++) = 'u';
- Buffer_AppendShortHexUnchecked(of, (ucs >> 10) + 0xd800);
+ Buffer_AppendShortHexUnchecked(of, (unsigned short) (ucs >> 10) + 0xd800);
of += 4;
*(of++) = '\\';
*(of++) = 'u';
- Buffer_AppendShortHexUnchecked(of, (ucs & 0x3ff) + 0xdc00);
+ Buffer_AppendShortHexUnchecked(of, (unsigned short) (ucs & 0x3ff) + 0xdc00);
of += 4;
}
else
{
*(of++) = '\\';
*(of++) = 'u';
- Buffer_AppendShortHexUnchecked(of, ucs);
+ Buffer_AppendShortHexUnchecked(of, (unsigned short) ucs);
of += 4;
}
}
-
- return FALSE;
}
#define Buffer_Reserve(__enc, __len) \
- if ((__enc)->end - (__enc)->offset < (__len)) \
+ if ( (size_t) ((__enc)->end - (__enc)->offset) < (size_t) (__len)) \
{ \
Buffer_Realloc((__enc), (__len));\
} \
@@ -529,7 +518,11 @@ int Buffer_AppendDoubleUnchecked(JSOBJ obj, JSONObjectEncoder *enc, double value
*/
if (value > thres_max)
{
- enc->offset += sprintf(str, "%.15e", neg ? -value : value);
+#ifdef _WIN32
+ enc->offset += sprintf_s(str, enc->end - enc->offset, "%.15e", neg ? -value : value);
+#else
+ enc->offset += snprintf(str, enc->end - enc->offset, "%.15e", neg ? -value : value);
+#endif
return TRUE;
}
@@ -659,7 +652,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
}
else
{
- if (!Buffer_EscapeStringUnvalidated(obj, enc, name, name + cbName))
+ if (!Buffer_EscapeStringUnvalidated(enc, name, name + cbName))
{
return;
}
@@ -815,7 +808,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
}
else
{
- if (!Buffer_EscapeStringUnvalidated(obj, enc, value, value + szlen))
+ if (!Buffer_EscapeStringUnvalidated(enc, value, value + szlen))
{
enc->endTypeContext(obj, &tc);
enc->level --;

0 comments on commit a1747b9

Please sign in to comment.