Commit 1ad5a8df authored by Olivier Bertrand's avatar Olivier Bertrand

Fix memory error when a plain string argument is parsed.

Parsing memory, not added in CalcLen, is added in CheckMemory.
Adding also the file length.
  modified:   storage/connect/jsonudf.cpp
parent 0ec89291
...@@ -28,8 +28,8 @@ tabvct.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp ...@@ -28,8 +28,8 @@ tabvct.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp
array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h
engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamvct.h filamzip.h engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamvct.h filamzip.h
filter.h global.h ha_connect.h inihandl.h json.h maputil.h msgid.h mycat.h filter.h global.h ha_connect.h inihandl.h json.h jsonudf.h maputil.h msgid.h
myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h mycat.h myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h
resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabjson.h tabmul.h tabmysql.h resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabjson.h tabmul.h tabmysql.h
taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvct.h tabvir.h tabxcl.h taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvct.h tabvir.h tabxcl.h
user_connect.h valblk.h value.h xindex.h xobject.h xtable.h) user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
......
...@@ -1263,7 +1263,7 @@ static int IsJson(UDF_ARGS *args, uint i) ...@@ -1263,7 +1263,7 @@ static int IsJson(UDF_ARGS *args, uint i)
static PGLOBAL GetMemPtr(PGLOBAL g, UDF_ARGS *args, uint i) static PGLOBAL GetMemPtr(PGLOBAL g, UDF_ARGS *args, uint i)
{ {
return (IsJson(args, i) == 3) ? ((PBSON)args->args[i])->G : g; return (IsJson(args, i) == 3) ? ((PBSON)args->args[i])->G : g;
} // end of IsJson } // end of GetMemPtr
/*********************************************************************************/ /*********************************************************************************/
/* GetFileLength: returns file size in number of bytes. */ /* GetFileLength: returns file size in number of bytes. */
...@@ -1408,18 +1408,32 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj, ...@@ -1408,18 +1408,32 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj,
/*********************************************************************************/ /*********************************************************************************/
/* Check if the calculated memory is enough. */ /* Check if the calculated memory is enough. */
/*********************************************************************************/ /*********************************************************************************/
static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n,
uint n, my_bool obj, my_bool mod = false) my_bool m, my_bool obj = false, my_bool mod = false)
{ {
unsigned long rl, ml; unsigned long rl, ml;
my_bool b = false;
n = MY_MIN(n, args->arg_count); n = MY_MIN(n, args->arg_count);
for (uint i = 0; i < n; i++) for (uint i = 0; i < n; i++)
if (IsJson(args, i) == 2) { if (IsJson(args, i) == 2 ||
(b = (m && !i && args->arg_type[0] == STRING_RESULT && !IsJson(args, 0)))) {
if (CalcLen(args, obj, rl, ml, mod)) if (CalcLen(args, obj, rl, ml, mod))
return true; return true;
else if (ml > g->Sarea_Size) { else if (b) {
ulong len;
char *p = args->args[0];
// Is this a file name?
if (!strchr("[{ \t\r\n", *p) && (len = GetFileLength(p)))
ml += len * (M + 1);
else
ml += args->lengths[0] * M;
} // endif b
if (ml > g->Sarea_Size) {
free(g->Sarea); free(g->Sarea);
if (!(g->Sarea = PlugAllocMem(g, ml))) { if (!(g->Sarea = PlugAllocMem(g, ml))) {
...@@ -1794,7 +1808,7 @@ char *json_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1794,7 +1808,7 @@ char *json_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!CheckMemory(g, initid, args, args->arg_count, true)) {
char *p; char *p;
PJSON top; PJSON top;
PJAR arp; PJAR arp;
...@@ -1878,7 +1892,7 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1878,7 +1892,7 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin; goto fin;
} // endif Xchk } // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, false, true)) {
int *x; int *x;
uint n = 2; uint n = 2;
PJSON jsp, top; PJSON jsp, top;
...@@ -1913,7 +1927,7 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1913,7 +1927,7 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = str; g->Xchk = str;
fin: fin:
if (!str) { if (!str) {
*res_length = 0; *res_length = 0;
*is_null = 1; *is_null = 1;
...@@ -1960,7 +1974,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1960,7 +1974,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin; goto fin;
} // endif Xchk } // endif Xchk
if (!CheckMemory(g, initid, args, 1, false, true)) { if (!CheckMemory(g, initid, args, 1, false, false, true)) {
int *x; int *x;
uint n = 1; uint n = 1;
PJSON top; PJSON top;
...@@ -1991,7 +2005,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1991,7 +2005,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = str; g->Xchk = str;
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
*error = 1; *error = 1;
...@@ -2025,7 +2039,7 @@ char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2025,7 +2039,7 @@ char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!CheckMemory(g, initid, args, args->arg_count, false, false, true)) {
PJOB objp = new(g)JOBJECT; PJOB objp = new(g)JOBJECT;
for (uint i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count; i++)
...@@ -2070,7 +2084,7 @@ char *json_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2070,7 +2084,7 @@ char *json_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) {
PJVAL jvp; PJVAL jvp;
PJOB objp = new(g)JOBJECT; PJOB objp = new(g)JOBJECT;
...@@ -2121,7 +2135,7 @@ char *json_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2121,7 +2135,7 @@ char *json_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) {
PJOB objp = new(g)JOBJECT; PJOB objp = new(g)JOBJECT;
for (uint i = 0; i < args->arg_count; i += 2) for (uint i = 0; i < args->arg_count; i += 2)
...@@ -2161,7 +2175,7 @@ my_bool json_object_add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2161,7 +2175,7 @@ my_bool json_object_add_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
strcpy(message, "First argument must be a json item"); strcpy(message, "First argument must be a json item");
return true; return true;
} else } else
CalcLen(args, false, reslen, memlen, true); CalcLen(args, true, reslen, memlen, true);
return JsonInit(initid, args, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of json_object_add_init } // end of json_object_add_init
...@@ -2178,7 +2192,7 @@ char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2178,7 +2192,7 @@ char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin; goto fin;
} // endif Xchk } // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, true, true)) {
PJOB jobp; PJOB jobp;
PJVAL jvp; PJVAL jvp;
PJSON jsp, top; PJSON jsp, top;
...@@ -2210,7 +2224,7 @@ char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2210,7 +2224,7 @@ char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = str; g->Xchk = str;
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
*error = 1; *error = 1;
...@@ -2243,7 +2257,7 @@ my_bool json_object_delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2243,7 +2257,7 @@ my_bool json_object_delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
strcpy(message, "Second argument must be a key string"); strcpy(message, "Second argument must be a key string");
return true; return true;
} else } else
CalcLen(args, false, reslen, memlen, true); CalcLen(args, true, reslen, memlen, true);
return JsonInit(initid, args, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of json_object_delete_init } // end of json_object_delete_init
...@@ -2260,7 +2274,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2260,7 +2274,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin; goto fin;
} // endif Xchk } // endif Xchk
if (!CheckMemory(g, initid, args, 1, false, true)) { if (!CheckMemory(g, initid, args, 1, false, true, true)) {
char *key; char *key;
PJOB jobp; PJOB jobp;
PJSON jsp, top; PJSON jsp, top;
...@@ -2290,7 +2304,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2290,7 +2304,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = str; g->Xchk = str;
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
*error = 1; *error = 1;
...@@ -2332,7 +2346,7 @@ char *json_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2332,7 +2346,7 @@ char *json_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->N) { if (!g->N) {
if (!CheckMemory(g, initid, args, 1, false)) { if (!CheckMemory(g, initid, args, 1, true, true)) {
char *p; char *p;
PJSON jsp; PJSON jsp;
PJVAL jvp = MakeValue(g, args, 0); PJVAL jvp = MakeValue(g, args, 0);
...@@ -2560,7 +2574,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2560,7 +2574,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin; goto fin;
} // endif Xchk } // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, false, true)) {
PJSON top; PJSON top;
PJVAL jvp; PJVAL jvp;
PJSON jsp[2] = {NULL, NULL}; PJSON jsp[2] = {NULL, NULL};
...@@ -2595,7 +2609,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2595,7 +2609,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = str; g->Xchk = str;
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
*error = 1; *error = 1;
...@@ -2648,7 +2662,10 @@ my_bool json_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2648,7 +2662,10 @@ my_bool json_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *) unsigned long *res_length, char *is_null, char *)
{ {
char *str = NULL; char *p, *path, *str = NULL;
PJSON jsp;
PJVAL jvp;
PJSNX jsx;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -2657,13 +2674,12 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2657,13 +2674,12 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
if (!g->Xchk) { if (!g->Xchk) {
PJVAL jvp = MakeValue(g, args, 0); if (CheckMemory(g, initid, args, 1, true, true)) {
PUSH_WARNING("CheckMemory error");
goto fin;
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { if (!(jsp = ParseJson(g, p, strlen(p)))) {
...@@ -2700,8 +2716,6 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2700,8 +2716,6 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Activityp = (PACTIVITY)str; g->Activityp = (PACTIVITY)str;
} // endif CheckMemory
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
...@@ -2762,8 +2776,11 @@ my_bool jsonget_string_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2762,8 +2776,11 @@ my_bool jsonget_string_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *) unsigned long *res_length, char *is_null, char *)
{ {
char *p, *path, *str = NULL;
int rc; int rc;
char *str = NULL; PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -2772,12 +2789,6 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2772,12 +2789,6 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
// Save stack and allocation environment and prepare error return // Save stack and allocation environment and prepare error return
if (g->jump_level == MAX_JUMP) { if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS)); PUSH_WARNING(MSG(TOO_MANY_JUMPS));
...@@ -2792,6 +2803,10 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2792,6 +2803,10 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc } // endif rc
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
goto err;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -2830,9 +2845,8 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2830,9 +2845,8 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
err: err:
g->jump_level--; g->jump_level--;
} // endif CheckMemory
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
*res_length = 0; *res_length = 0;
...@@ -2875,6 +2889,11 @@ my_bool jsonget_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2875,6 +2889,11 @@ my_bool jsonget_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error) char *is_null, char *error)
{ {
char *p, *path;
long long n;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -2887,14 +2906,13 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, ...@@ -2887,14 +2906,13 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
long long n;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
if (g->Mrr) *error = 1;
*is_null = 1;
return 0LL;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -2928,7 +2946,6 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, ...@@ -2928,7 +2946,6 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
jsx->ReadValue(g); jsx->ReadValue(g);
if (jsx->GetValue()->IsNull()) { if (jsx->GetValue()->IsNull()) {
// PUSH_WARNING("Value not found");
*is_null = 1; *is_null = 1;
return 0; return 0;
} // endif IsNull } // endif IsNull
...@@ -2943,11 +2960,6 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, ...@@ -2943,11 +2960,6 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
} // endif const_item } // endif const_item
return n; return n;
} // endif CheckMemory
if (g->Mrr) *error = 1;
*is_null = 1;
return 0LL;
} // end of jsonget_int } // end of jsonget_int
void jsonget_int_deinit(UDF_INIT* initid) void jsonget_int_deinit(UDF_INIT* initid)
...@@ -2992,6 +3004,11 @@ my_bool jsonget_real_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2992,6 +3004,11 @@ my_bool jsonget_real_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error) char *is_null, char *error)
{ {
char *p, *path;
double d;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -3004,14 +3021,13 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, ...@@ -3004,14 +3021,13 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
double d;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
if (g->Mrr) *error = 1;
*is_null = 1;
return 0.0;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -3044,7 +3060,6 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, ...@@ -3044,7 +3060,6 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
jsx->ReadValue(g); jsx->ReadValue(g);
if (jsx->GetValue()->IsNull()) { if (jsx->GetValue()->IsNull()) {
// PUSH_WARNING("Value not found");
*is_null = 1; *is_null = 1;
return 0.0; return 0.0;
} // endif IsNull } // endif IsNull
...@@ -3059,11 +3074,6 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, ...@@ -3059,11 +3074,6 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
} // endif const_item } // endif const_item
return d; return d;
} // endif CheckMemory
if (g->Mrr) *error = 1;
*is_null = 1;
return 0.0;
} // end of jsonget_real } // end of jsonget_real
void jsonget_real_deinit(UDF_INIT* initid) void jsonget_real_deinit(UDF_INIT* initid)
...@@ -3105,7 +3115,11 @@ my_bool jsonlocate_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -3105,7 +3115,11 @@ my_bool jsonlocate_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error) unsigned long *res_length, char *is_null, char *error)
{ {
char *path = NULL; char *p, *path = NULL;
int k, rc;
PJVAL jvp, jvp2;
PJSON jsp;
PJSNX jsx;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -3122,13 +3136,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3122,13 +3136,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p;
int k, rc;
PJVAL jvp, jvp2;
PJSON jsp;
PJSNX jsx;
// Save stack and allocation environment and prepare error return // Save stack and allocation environment and prepare error return
if (g->jump_level == MAX_JUMP) { if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS)); PUSH_WARNING(MSG(TOO_MANY_JUMPS));
...@@ -3145,6 +3152,11 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3145,6 +3152,11 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc } // endif rc
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, !g->Xchk)) {
PUSH_WARNING("CheckMemory error");
*error = 1;
goto err;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -3186,11 +3198,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3186,11 +3198,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
*res_length = strlen(path); *res_length = strlen(path);
return path; return path;
} // endif CheckMemory
*error = 1;
*is_null = 1;
return NULL;
} // end of jsonlocate } // end of jsonlocate
void jsonlocate_deinit(UDF_INIT* initid) void jsonlocate_deinit(UDF_INIT* initid)
...@@ -3232,7 +3239,11 @@ my_bool json_locate_all_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -3232,7 +3239,11 @@ my_bool json_locate_all_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error) unsigned long *res_length, char *is_null, char *error)
{ {
char *path = NULL; char *p, *path = NULL;
int rc, mx = 10;
PJVAL jvp, jvp2;
PJSON jsp;
PJSNX jsx;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -3250,13 +3261,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3250,13 +3261,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p;
int rc, mx = 10;
PJVAL jvp, jvp2;
PJSON jsp;
PJSNX jsx;
// Save stack and allocation environment and prepare error return // Save stack and allocation environment and prepare error return
if (g->jump_level == MAX_JUMP) { if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS)); PUSH_WARNING(MSG(TOO_MANY_JUMPS));
...@@ -3273,6 +3277,11 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3273,6 +3277,11 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc } // endif rc
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
*error = 1;
goto err;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -3315,11 +3324,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3315,11 +3324,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
*res_length = strlen(path); *res_length = strlen(path);
return path; return path;
} // endif CheckMemory
*error = 1;
*is_null = 1;
return NULL;
} // end of json_locate_all } // end of json_locate_all
void json_locate_all_deinit(UDF_INIT* initid) void json_locate_all_deinit(UDF_INIT* initid)
...@@ -3416,6 +3420,11 @@ my_bool jsoncontains_path_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -3416,6 +3420,11 @@ my_bool jsoncontains_path_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error) unsigned long *res_length, char *is_null, char *error)
{ {
char *p, *path;
long long n;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
...@@ -3428,22 +3437,17 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3428,22 +3437,17 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
long long n;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
goto err;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
if (g->Mrr) *error = 1; goto err;
*is_null = 1;
return 0;
} // endif jsp } // endif jsp
} else } else
...@@ -3462,8 +3466,7 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3462,8 +3466,7 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (jsx->SetJpath(g, path)) { if (jsx->SetJpath(g, path)) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
*is_null = 1; goto err;
return 0;
} // endif SetJpath } // endif SetJpath
n = (jsx->CheckPath(g)) ? 1LL : 0LL; n = (jsx->CheckPath(g)) ? 1LL : 0LL;
...@@ -3476,8 +3479,8 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3476,8 +3479,8 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif const_item } // endif const_item
return n; return n;
} // endif CheckMemory
err:
if (g->Mrr) *error = 1; if (g->Mrr) *error = 1;
*is_null = 1; *is_null = 1;
return 0LL; return 0LL;
...@@ -3522,10 +3525,14 @@ my_bool json_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -3522,10 +3525,14 @@ my_bool json_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error) unsigned long *res_length, char *is_null, char *error)
{ {
char *p, *path, *str = NULL;
int w, rc; int w, rc;
my_bool b = true; my_bool b = true;
char *str = NULL; PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
PGLOBAL gb = GetMemPtr(g, args, 0);
if (g->N) { if (g->N) {
str = (char*)g->Activityp; str = (char*)g->Activityp;
...@@ -3540,18 +3547,11 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3540,18 +3547,11 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
else else
w = 0; w = 0;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL gb = GetMemPtr(g, args, 0);
// Save stack and allocation environment and prepare error return // Save stack and allocation environment and prepare error return
if (g->jump_level == MAX_JUMP) { if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS)); PUSH_WARNING(MSG(TOO_MANY_JUMPS));
*is_null = 1; *error = 1;
return NULL; goto fin;
} // endif jump_level } // endif jump_level
if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) { if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) {
...@@ -3561,6 +3561,10 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3561,6 +3561,10 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc } // endif rc
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true, false, true)) {
PUSH_WARNING("CheckMemory error");
goto err;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -3612,9 +3616,8 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3612,9 +3616,8 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
err: err:
g->jump_level--; g->jump_level--;
} // endif CheckMemory
fin: fin:
if (!str) { if (!str) {
*is_null = 1; *is_null = 1;
*res_length = 0; *res_length = 0;
...@@ -3770,7 +3773,7 @@ char *json_file(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3770,7 +3773,7 @@ char *json_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = str; g->Xchk = str;
fin: fin:
if (!str) { if (!str) {
*res_length = 0; *res_length = 0;
*is_null = 1; *is_null = 1;
...@@ -3807,7 +3810,7 @@ my_bool jfile_make_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -3807,7 +3810,7 @@ my_bool jfile_make_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *) unsigned long *res_length, char *is_null, char *)
{ {
char *p, *str, *msg, *fn = NULL; char *p, *msg, *str = NULL, *fn = NULL;
int n, pretty = 2; int n, pretty = 2;
PJSON jsp; PJSON jsp;
PJVAL jvp; PJVAL jvp;
...@@ -3819,8 +3822,6 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3819,8 +3822,6 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
PlugSubSet(g, g->Sarea, g->Sarea_Size);
if ((n = IsJson(args, 0)) == 3) { if ((n = IsJson(args, 0)) == 3) {
// Get default file name and pretty // Get default file name and pretty
PBSON bsp = (PBSON)args->args[0]; PBSON bsp = (PBSON)args->args[0];
...@@ -3831,6 +3832,10 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3831,6 +3832,10 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
fn = args->args[0]; fn = args->args[0];
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
goto fin;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
...@@ -3838,7 +3843,7 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3838,7 +3843,7 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Is this a file name? // Is this a file name?
if (!(p = GetJsonFile(g, p))) { if (!(p = GetJsonFile(g, p))) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
return NULL; goto fin;
} else } else
fn = jvp->GetString(); fn = jvp->GetString();
...@@ -3846,7 +3851,7 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3846,7 +3851,7 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (!(jsp = ParseJson(g, p, strlen(p)))) { if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
return NULL; goto fin;
} // endif jsp } // endif jsp
jvp->SetValue(jsp); jvp->SetValue(jsp);
...@@ -3965,7 +3970,7 @@ char *jbin_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -3965,7 +3970,7 @@ char *jbin_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk; PBSON bsp = (PBSON)g->Xchk;
if (!bsp || bsp->Changed) { if (!bsp || bsp->Changed) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!CheckMemory(g, initid, args, args->arg_count, true)) {
char *p; char *p;
PJSON top; PJSON top;
PJAR arp; PJAR arp;
...@@ -4042,7 +4047,7 @@ char *jbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4042,7 +4047,7 @@ char *jbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp; return (char*)bsp;
} // endif bsp } // endif bsp
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, false, true)) {
int *x = NULL; int *x = NULL;
uint n = 2; uint n = 2;
// PJSON jsp; // PJSON jsp;
...@@ -4111,7 +4116,7 @@ char *jbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4111,7 +4116,7 @@ char *jbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp; return (char*)bsp;
} // endif bsp } // endif bsp
if (!CheckMemory(g, initid, args, 1, false, true)) { if (!CheckMemory(g, initid, args, 1, false, false, true)) {
int *x; int *x;
uint n = 1; uint n = 1;
PJAR arp; PJAR arp;
...@@ -4224,7 +4229,7 @@ char *jbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4224,7 +4229,7 @@ char *jbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk; PBSON bsp = (PBSON)g->Xchk;
if (!bsp || bsp->Changed) { if (!bsp || bsp->Changed) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) {
PJVAL jvp; PJVAL jvp;
PJOB objp = new(g)JOBJECT; PJOB objp = new(g)JOBJECT;
...@@ -4281,7 +4286,7 @@ char *jbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4281,7 +4286,7 @@ char *jbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk; PBSON bsp = (PBSON)g->Xchk;
if (!bsp || bsp->Changed) { if (!bsp || bsp->Changed) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) {
PJOB objp = new(g)JOBJECT; PJOB objp = new(g)JOBJECT;
for (uint i = 0; i < args->arg_count; i += 2) for (uint i = 0; i < args->arg_count; i += 2)
...@@ -4335,7 +4340,7 @@ char *jbin_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4335,7 +4340,7 @@ char *jbin_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp; return (char*)bsp;
} // endif bsp } // endif bsp
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, true, true)) {
char *key; char *key;
PJOB jobp; PJOB jobp;
PJVAL jvp = MakeValue(g, args, 0, &top); PJVAL jvp = MakeValue(g, args, 0, &top);
...@@ -4401,7 +4406,7 @@ char *jbin_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4401,7 +4406,7 @@ char *jbin_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp; return (char*)bsp;
} // endif bsp } // endif bsp
if (!CheckMemory(g, initid, args, 1, false, true)) { if (!CheckMemory(g, initid, args, 1, false, true, true)) {
char *key; char *key;
PJOB jobp; PJOB jobp;
PJVAL jvp = MakeValue(g, args, 0, &top); PJVAL jvp = MakeValue(g, args, 0, &top);
...@@ -4458,7 +4463,7 @@ char *jbin_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4458,7 +4463,7 @@ char *jbin_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk; PBSON bsp = (PBSON)g->Xchk;
if (!bsp || bsp->Changed) { if (!bsp || bsp->Changed) {
if (!CheckMemory(g, initid, args, 1, false)) { if (!CheckMemory(g, initid, args, 1, true, true)) {
char *p; char *p;
PJSON jsp; PJSON jsp;
PJVAL jvp = MakeValue(g, args, 0); PJVAL jvp = MakeValue(g, args, 0);
...@@ -4514,8 +4519,12 @@ my_bool jbin_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -4514,8 +4519,12 @@ my_bool jbin_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error) unsigned long *res_length, char *is_null, char *error)
{ {
PGLOBAL g = (PGLOBAL)initid->ptr; char *p, *path;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PBSON bsp = NULL; PBSON bsp = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) { if (g->N) {
bsp = (PBSON)g->Activityp; bsp = (PBSON)g->Activityp;
...@@ -4523,19 +4532,17 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4523,19 +4532,17 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item) } else if (initid->const_item)
g->N = 1; g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true, true)) {
PUSH_WARNING("CheckMemory error");
goto fin;
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
return NULL; goto fin;
} // endif jsp } // endif jsp
} else } else
...@@ -4554,8 +4561,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4554,8 +4561,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (jsx->SetJpath(g, path, false)) { if (jsx->SetJpath(g, path, false)) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
*is_null = 1; goto fin;
return NULL;
} // endif SetJpath } // endif SetJpath
// Get the json tree // Get the json tree
...@@ -4573,9 +4579,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4573,9 +4579,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Activityp = (PACTIVITY)bsp; g->Activityp = (PACTIVITY)bsp;
} // endif CheckMemory fin:
fin:
if (!bsp) { if (!bsp) {
*is_null = 1; *is_null = 1;
*res_length = 0; *res_length = 0;
...@@ -4611,7 +4615,7 @@ char *jbin_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4611,7 +4615,7 @@ char *jbin_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp; return (char*)bsp;
} // endif bsp } // endif bsp
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, false, true)) {
PJVAL jvp; PJVAL jvp;
PJSON jsp[2] = {NULL, NULL}; PJSON jsp[2] = {NULL, NULL};
PGLOBAL gb = GetMemPtr(g, args, 0); PGLOBAL gb = GetMemPtr(g, args, 0);
...@@ -4666,10 +4670,15 @@ my_bool jbin_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -4666,10 +4670,15 @@ my_bool jbin_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error) unsigned long *res_length, char *is_null, char *error)
{ {
char *p, *path;
int w; int w;
my_bool b = true; my_bool b = true;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PBSON bsp = NULL; PBSON bsp = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
PGLOBAL gb = GetMemPtr(g, args, 0);
if (g->N) { if (g->N) {
bsp = (PBSON)g->Activityp; bsp = (PBSON)g->Activityp;
...@@ -4684,20 +4693,16 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4684,20 +4693,16 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
else else
w = 0; w = 0;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL gb = GetMemPtr(g, args, 0);
if (!g->Xchk) { if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true, false, true)) {
PUSH_WARNING("CheckMemory error");
} else
jvp = MakeValue(g, args, 0); jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
return NULL; goto fin;
} // endif jsp } // endif jsp
} else } else
...@@ -4740,9 +4745,7 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4740,9 +4745,7 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Activityp = (PACTIVITY)bsp; g->Activityp = (PACTIVITY)bsp;
} // endif CheckMemory fin:
fin:
if (!bsp) { if (!bsp) {
*is_null = 1; *is_null = 1;
*res_length = 0; *res_length = 0;
...@@ -4889,7 +4892,7 @@ char *jbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4889,7 +4892,7 @@ char *jbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function // Keep result of constant function
g->Xchk = bsp; g->Xchk = bsp;
fin: fin:
if (!bsp) { if (!bsp) {
*res_length = 0; *res_length = 0;
*is_null = 1; *is_null = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment