@@ -275,9 +275,13 @@ static inline void PutStr( CBuffer *buffer, const string_t &str )
275275#ifdef SQDBG_VALIDATE_SENT_MSG
276276 for ( unsigned int i = 0 ; i < str.len ; i++ )
277277 {
278- AssertMsg ( IN_RANGE_CHAR ( str.ptr [i], 0x20 , 0x7E ) &&
279- ( ( str.ptr [i] != ' \\ ' && str.ptr [i] != ' \" ' ) || ( i && str.ptr [i-1 ] == ' \\ ' ) ),
280- " control char in json string" );
278+ if ( str.ptr [i] == ' \\ ' && ( str.ptr [i+1 ] == ' \\ ' || str.ptr [i+1 ] == ' \" ' ) )
279+ {
280+ i++;
281+ continue ;
282+ }
283+
284+ AssertMsg ( str.ptr [i] != ' \\ ' && IN_RANGE_CHAR ( str.ptr [i], 0x20 , 0x7E ), " control char in json string" );
281285 }
282286#endif
283287}
@@ -433,7 +437,7 @@ static inline void PutStr( CBuffer *buffer, const string_t &str, bool quote )
433437 idx += printhex< true , false >(
434438 mem + idx,
435439 buffer->Capacity () - idx,
436- (SQChar )*(unsigned char *)c );
440+ (SQUnsignedChar )*(unsigned char *)c );
437441 }
438442 }
439443 }
@@ -503,6 +507,7 @@ static inline void PutInt( CBuffer *buffer, I val )
503507template < bool padding, typename I >
504508static inline void PutHex ( CBuffer *buffer, I val )
505509{
510+ STATIC_ASSERT ( IS_UNSIGNED ( I ) );
506511 buffer->base .Ensure ( buffer->Size () + countdigits<16 >( val ) + 1 );
507512 int len = printhex< padding >( buffer->Base () + buffer->Size (), buffer->Capacity () - buffer->Size (), val );
508513 buffer->size += len;
@@ -699,7 +704,7 @@ class wjson_table_t : public wjson_t
699704 }
700705 else
701706 {
702- PutHex< false >( m_pBuffer, val );
707+ PutHex< false >( m_pBuffer, cast_unsigned ( I, val ) );
703708 }
704709 PutChar ( m_pBuffer, ' ]' );
705710 PutChar ( m_pBuffer, ' \" ' );
@@ -850,7 +855,7 @@ class JSONParser
850855 else
851856 {
852857 buf = m_Allocator->Alloc (5 );
853- int i = printhex< true , true , false >( buf, 5 , token );
858+ int i = printhex< true , true , false >( buf, 5 , ( unsigned char ) token );
854859 Assert ( i == 4 );
855860 buf[i] = 0 ;
856861 }
@@ -877,6 +882,24 @@ class JSONParser
877882 m_error[len] = 0 ;
878883 }
879884
885+ bool IsValue ( char token )
886+ {
887+ switch ( token )
888+ {
889+ case Token_String:
890+ case Token_Integer:
891+ case Token_Float:
892+ case Token_False:
893+ case Token_True:
894+ case Token_Null:
895+ case Token_Table:
896+ case Token_Array:
897+ return true ;
898+ default :
899+ return false ;
900+ }
901+ }
902+
880903 char NextToken ( string_t &token )
881904 {
882905 while ( m_cur < m_end )
@@ -1206,7 +1229,7 @@ class JSONParser
12061229 type = NextToken ( token );
12071230 type = ParseValue ( type, token, &kv->val );
12081231
1209- if ( type == Token_Error )
1232+ if ( ! IsValue ( type ) )
12101233 {
12111234 SetError ( " invalid token %s @ %i" , Char (type), Index () );
12121235 return Token_Error;
@@ -1239,7 +1262,7 @@ class JSONParser
12391262
12401263 for (;;)
12411264 {
1242- if ( type == Token_Error )
1265+ if ( ! IsValue ( type ) )
12431266 {
12441267 SetError ( " expected '%c', got %s @ %i" , ' ]' , Char (type), Index () );
12451268 return Token_Error;
@@ -1315,7 +1338,7 @@ class JSONParser
13151338 value->type = JSON_NULL;
13161339 return type;
13171340 default :
1318- return type ;
1341+ return Token_Error ;
13191342 }
13201343 }
13211344};
0 commit comments