mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ci: fix clang sanitize errors for json_decode
This commit is contained in:
parent
11ccf06441
commit
2ecfd1b351
5
thirdparty/cJSON/cJSON.c
vendored
5
thirdparty/cJSON/cJSON.c
vendored
@ -74,6 +74,11 @@ typedef struct {
|
|||||||
} error;
|
} error;
|
||||||
static error global_error = { NULL, 0 };
|
static error global_error = { NULL, 0 };
|
||||||
|
|
||||||
|
CJSON_PUBLIC(size_t) cJSON_GetErrorPos(void)
|
||||||
|
{
|
||||||
|
return global_error.position;
|
||||||
|
}
|
||||||
|
|
||||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
|
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
|
||||||
{
|
{
|
||||||
return (const char*) (global_error.json + global_error.position);
|
return (const char*) (global_error.json + global_error.position);
|
||||||
|
1
thirdparty/cJSON/cJSON.h
vendored
1
thirdparty/cJSON/cJSON.h
vendored
@ -172,6 +172,7 @@ CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const objec
|
|||||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||||
|
CJSON_PUBLIC(size_t) cJSON_GetErrorPos(void);
|
||||||
|
|
||||||
/* Check if the item is a string and return its valuestring */
|
/* Check if the item is a string and return its valuestring */
|
||||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
|
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
|
||||||
|
@ -73,27 +73,29 @@ $dec_fn_dec {
|
|||||||
if (!root) {
|
if (!root) {
|
||||||
const char *error_ptr = cJSON_GetErrorPtr();
|
const char *error_ptr = cJSON_GetErrorPtr();
|
||||||
if (error_ptr != NULL) {
|
if (error_ptr != NULL) {
|
||||||
char *prevline_ptr = (char*)error_ptr;
|
const size_t error_pos = cJSON_GetErrorPos();
|
||||||
int maxcontext_chars = 30;
|
int maxcontext_chars = 30;
|
||||||
int backlines = 1;
|
byte *buf = vcalloc_noscan(maxcontext_chars + 10);
|
||||||
int backchars = maxcontext_chars-7;
|
if(error_pos > 0) {
|
||||||
while(backchars--){
|
int backlines = 1;
|
||||||
char prevc = *(prevline_ptr - 1);
|
int backchars = error_pos < maxcontext_chars-7 ? (int)error_pos : maxcontext_chars-7 ;
|
||||||
if(0==prevc){
|
char *prevline_ptr = (char*)error_ptr;
|
||||||
break;
|
while(backchars--){
|
||||||
}
|
char prevc = *(prevline_ptr - 1);
|
||||||
if(10==prevc && !backlines--){
|
if(0==prevc){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prevline_ptr--;
|
if(10==prevc && !backlines--){
|
||||||
if(123==prevc) {
|
break;
|
||||||
break; // stop at `{` too
|
}
|
||||||
}
|
prevline_ptr--;
|
||||||
|
if(123==prevc) {
|
||||||
|
break; // stop at `{` too
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int maxchars = vstrlen_char(prevline_ptr);
|
||||||
|
vmemcpy(buf, prevline_ptr, (maxchars < maxcontext_chars ? maxchars : maxcontext_chars));
|
||||||
}
|
}
|
||||||
byte *buf = _v_malloc(maxcontext_chars + 10);
|
|
||||||
vmemset(buf, 0, maxcontext_chars+10);
|
|
||||||
vmemcpy(buf, prevline_ptr, maxcontext_chars);
|
|
||||||
// for(int x=-10;x<10;x++){ char *xx = prevline_ptr+x; fprintf(stderr, "2 prevline_ptr + %d: %p | %c | %d \\n", x, xx, (int)(*(xx)), (int)(*(xx))); } fprintf(stderr, "--------\\n");
|
|
||||||
return (Option_$styp){.state = 2,.err = _v_error(tos2(buf)),.data = {0}};
|
return (Option_$styp){.state = 2,.err = _v_error(tos2(buf)),.data = {0}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user