Fix rjp_string containing incorrect length

This commit is contained in:
rexy712
2019-02-21 10:49:21 -08:00
parent fd7d9988b8
commit d2ea9f5c79
3 changed files with 10 additions and 8 deletions

View File

@@ -23,7 +23,7 @@
#include <stddef.h> //size_t
int _rjp__is_whitespace(char c);
char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, int* column);
char* _rjp__parse_string(RJP_value* root, const char* str, int* inclen, int* len, int* row, int* column);
size_t _rjp__array_strlen(RJP_value* arr);
size_t _rjp__object_strlen(RJP_value* root);
size_t _rjp__value_strlen(RJP_value* root);

View File

@@ -104,14 +104,15 @@ RJP_value* rjp_parse(const char* str){
syntax_error("Key found outside of object definition!", row, column);
int keylen;
char* new_string = _rjp__parse_string(root, ++str, &keylen, &row, &column);
int inclen;
char* new_string = _rjp__parse_string(root, ++str, &inclen, &keylen, &row, &column);
if(!new_string){
if(!keylen)
syntax_error("Cannot have empty key name!", row, column);
return NULL;
}
_rjp__add_member_no_alloc(&curr->object, new_string, keylen);
str += keylen;
str += inclen;
*top = json_colon;
//end of this object (object is empty)
}else if(c == '}'){
@@ -183,9 +184,9 @@ RJP_value* rjp_parse(const char* str){
}
//strings
else if(c == '"'){
int vallen;
int vallen, inclen;
++str;
char* new_string = _rjp__parse_string(root, str, &vallen, &row, &column);
char* new_string = _rjp__parse_string(root, str, &inclen, &vallen, &row, &column);
if(!new_string){
if(vallen == 0){
new_string = rjp_calloc(1, 1);
@@ -194,7 +195,7 @@ RJP_value* rjp_parse(const char* str){
}
}
_rjp__add_value(curr, rjp_string(new_string, vallen));
str += vallen;
str += inclen;
*top = json_comma;
}
//numbers

View File

@@ -148,7 +148,7 @@ static uint32_t u8_to_codepoint(char* u){
}
//Convert escape sequences in strings
char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, int* column){
char* _rjp__parse_string(RJP_value* root, const char* str, int* inclen, int* len, int* row, int* column){
char* new_string;
++(*column); //account for starting quotation mark
int oldpos = 0;
@@ -173,7 +173,8 @@ char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, i
*column = 0;
}
}
*len = oldpos;
*inclen = oldpos;
*len = newpos;
if(newpos == 0){
return NULL;
}