Commit d3dc52e4 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.
  modified:   storage/connect/jsonudf.cpp
parent 27f9d2f9
......@@ -1263,7 +1263,7 @@ static int IsJson(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;
} // end of IsJson
} // end of GetMemPtr
/*********************************************************************************/
/* GetFileLength: returns file size in number of bytes. */
......@@ -1408,18 +1408,23 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj,
/*********************************************************************************/
/* Check if the calculated memory is enough. */
/*********************************************************************************/
static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args,
uint n, my_bool obj, my_bool mod = false)
static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n,
my_bool m, my_bool obj = false, my_bool mod = false)
{
unsigned long rl, ml;
my_bool b = false;
n = MY_MIN(n, args->arg_count);
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))
return true;
else if (ml > g->Sarea_Size) {
else if (b)
ml += args->lengths[0] * M; // Was not done in CalcLen
if (ml > g->Sarea_Size) {
free(g->Sarea);
if (!(g->Sarea = PlugAllocMem(g, ml))) {
......@@ -1794,7 +1799,7 @@ char *json_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) {
char *p;
PJSON top;
PJAR arp;
......@@ -1878,7 +1883,7 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin;
} // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) {
if (!CheckMemory(g, initid, args, 2, false, false, true)) {
int *x;
uint n = 2;
PJSON jsp, top;
......@@ -1913,7 +1918,7 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = str;
fin:
fin:
if (!str) {
*res_length = 0;
*is_null = 1;
......@@ -1960,7 +1965,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin;
} // endif Xchk
if (!CheckMemory(g, initid, args, 1, false, true)) {
if (!CheckMemory(g, initid, args, 1, false, false, true)) {
int *x;
uint n = 1;
PJSON top;
......@@ -1991,7 +1996,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = str;
fin:
fin:
if (!str) {
*is_null = 1;
*error = 1;
......@@ -2025,7 +2030,7 @@ char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr;
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;
for (uint i = 0; i < args->arg_count; i++)
......@@ -2070,7 +2075,7 @@ char *json_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) {
if (!CheckMemory(g, initid, args, args->arg_count, false, true)) {
PJVAL jvp;
PJOB objp = new(g)JOBJECT;
......@@ -2121,7 +2126,7 @@ char *json_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr;
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;
for (uint i = 0; i < args->arg_count; i += 2)
......@@ -2161,7 +2166,7 @@ my_bool json_object_add_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
strcpy(message, "First argument must be a json item");
return true;
} else
CalcLen(args, false, reslen, memlen, true);
CalcLen(args, true, reslen, memlen, true);
return JsonInit(initid, args, message, true, reslen, memlen);
} // end of json_object_add_init
......@@ -2178,7 +2183,7 @@ char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin;
} // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) {
if (!CheckMemory(g, initid, args, 2, false, true, true)) {
PJOB jobp;
PJVAL jvp;
PJSON jsp, top;
......@@ -2210,7 +2215,7 @@ char *json_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = str;
fin:
fin:
if (!str) {
*is_null = 1;
*error = 1;
......@@ -2243,7 +2248,7 @@ my_bool json_object_delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
strcpy(message, "Second argument must be a key string");
return true;
} else
CalcLen(args, false, reslen, memlen, true);
CalcLen(args, true, reslen, memlen, true);
return JsonInit(initid, args, message, true, reslen, memlen);
} // end of json_object_delete_init
......@@ -2260,7 +2265,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin;
} // endif Xchk
if (!CheckMemory(g, initid, args, 1, false, true)) {
if (!CheckMemory(g, initid, args, 1, false, true, true)) {
char *key;
PJOB jobp;
PJSON jsp, top;
......@@ -2290,7 +2295,7 @@ char *json_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = str;
fin:
fin:
if (!str) {
*is_null = 1;
*error = 1;
......@@ -2332,7 +2337,7 @@ char *json_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result,
PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->N) {
if (!CheckMemory(g, initid, args, 1, false)) {
if (!CheckMemory(g, initid, args, 1, true, true)) {
char *p;
PJSON jsp;
PJVAL jvp = MakeValue(g, args, 0);
......@@ -2560,7 +2565,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto fin;
} // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) {
if (!CheckMemory(g, initid, args, 2, false, false, true)) {
PJSON top;
PJVAL jvp;
PJSON jsp[2] = {NULL, NULL};
......@@ -2595,7 +2600,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = str;
fin:
fin:
if (!str) {
*is_null = 1;
*error = 1;
......@@ -2648,7 +2653,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,
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;
if (g->N) {
......@@ -2657,13 +2665,12 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item)
g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
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 (!(jsp = ParseJson(g, p, strlen(p)))) {
......@@ -2700,8 +2707,6 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Activityp = (PACTIVITY)str;
} // endif CheckMemory
fin:
if (!str) {
*is_null = 1;
......@@ -2762,8 +2767,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,
unsigned long *res_length, char *is_null, char *)
{
char *p, *path, *str = NULL;
int rc;
char *str = NULL;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
......@@ -2772,12 +2780,6 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item)
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
if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS));
......@@ -2792,6 +2794,10 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc
if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
goto err;
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) {
......@@ -2830,9 +2836,8 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result,
err:
g->jump_level--;
} // endif CheckMemory
fin:
fin:
if (!str) {
*is_null = 1;
*res_length = 0;
......@@ -2875,6 +2880,11 @@ my_bool jsonget_int_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error)
{
char *p, *path;
long long n;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
......@@ -2887,14 +2897,13 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
} else if (initid->const_item)
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 (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);
if ((p = jvp->GetString())) {
......@@ -2928,7 +2937,6 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
jsx->ReadValue(g);
if (jsx->GetValue()->IsNull()) {
// PUSH_WARNING("Value not found");
*is_null = 1;
return 0;
} // endif IsNull
......@@ -2943,11 +2951,6 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args,
} // endif const_item
return n;
} // endif CheckMemory
if (g->Mrr) *error = 1;
*is_null = 1;
return 0LL;
} // end of jsonget_int
void jsonget_int_deinit(UDF_INIT* initid)
......@@ -2992,6 +2995,11 @@ my_bool jsonget_real_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error)
{
char *p, *path;
double d;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
......@@ -3004,14 +3012,13 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
} else if (initid->const_item)
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 (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);
if ((p = jvp->GetString())) {
......@@ -3044,7 +3051,6 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
jsx->ReadValue(g);
if (jsx->GetValue()->IsNull()) {
// PUSH_WARNING("Value not found");
*is_null = 1;
return 0.0;
} // endif IsNull
......@@ -3059,11 +3065,6 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args,
} // endif const_item
return d;
} // endif CheckMemory
if (g->Mrr) *error = 1;
*is_null = 1;
return 0.0;
} // end of jsonget_real
void jsonget_real_deinit(UDF_INIT* initid)
......@@ -3105,7 +3106,11 @@ my_bool jsonlocate_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
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;
if (g->N) {
......@@ -3122,13 +3127,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item)
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
if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS));
......@@ -3145,6 +3143,11 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc
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);
if ((p = jvp->GetString())) {
......@@ -3186,11 +3189,6 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result,
*res_length = strlen(path);
return path;
} // endif CheckMemory
*error = 1;
*is_null = 1;
return NULL;
} // end of jsonlocate
void jsonlocate_deinit(UDF_INIT* initid)
......@@ -3232,7 +3230,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,
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;
if (g->N) {
......@@ -3250,13 +3252,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item)
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
if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS));
......@@ -3273,6 +3268,11 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc
if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
*error = 1;
goto err;
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) {
......@@ -3315,11 +3315,6 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result,
*res_length = strlen(path);
return path;
} // endif CheckMemory
*error = 1;
*is_null = 1;
return NULL;
} // end of json_locate_all
void json_locate_all_deinit(UDF_INIT* initid)
......@@ -3416,6 +3411,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,
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;
if (g->N) {
......@@ -3428,22 +3428,17 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item)
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 (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
goto err;
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
if (g->Mrr) *error = 1;
*is_null = 1;
return 0;
goto err;
} // endif jsp
} else
......@@ -3462,8 +3457,7 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (jsx->SetJpath(g, path)) {
PUSH_WARNING(g->Message);
*is_null = 1;
return 0;
goto err;
} // endif SetJpath
n = (jsx->CheckPath(g)) ? 1LL : 0LL;
......@@ -3476,8 +3470,8 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif const_item
return n;
} // endif CheckMemory
err:
if (g->Mrr) *error = 1;
*is_null = 1;
return 0LL;
......@@ -3522,10 +3516,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,
unsigned long *res_length, char *is_null, char *error)
{
char *p, *path, *str = NULL;
int w, rc;
my_bool b = true;
char *str = NULL;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr;
PGLOBAL gb = GetMemPtr(g, args, 0);
if (g->N) {
str = (char*)g->Activityp;
......@@ -3540,18 +3538,11 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
else
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
if (g->jump_level == MAX_JUMP) {
PUSH_WARNING(MSG(TOO_MANY_JUMPS));
*is_null = 1;
return NULL;
*error = 1;
goto fin;
} // endif jump_level
if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) {
......@@ -3561,6 +3552,10 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif rc
if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true, false, true)) {
PUSH_WARNING("CheckMemory error");
goto err;
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) {
......@@ -3612,9 +3607,8 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
err:
g->jump_level--;
} // endif CheckMemory
fin:
fin:
if (!str) {
*is_null = 1;
*res_length = 0;
......@@ -3770,7 +3764,7 @@ char *json_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = str;
fin:
fin:
if (!str) {
*res_length = 0;
*is_null = 1;
......@@ -3807,7 +3801,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,
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;
PJSON jsp;
PJVAL jvp;
......@@ -3831,6 +3825,10 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
fn = args->args[0];
if (!g->Xchk) {
if (CheckMemory(g, initid, args, 1, true)) {
PUSH_WARNING("CheckMemory error");
goto fin;
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) {
......@@ -3838,7 +3836,7 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Is this a file name?
if (!(p = GetJsonFile(g, p))) {
PUSH_WARNING(g->Message);
return NULL;
goto fin;
} else
fn = jvp->GetString();
......@@ -3846,7 +3844,7 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
return NULL;
goto fin;
} // endif jsp
jvp->SetValue(jsp);
......@@ -3965,7 +3963,7 @@ char *jbin_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk;
if (!bsp || bsp->Changed) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) {
if (!CheckMemory(g, initid, args, args->arg_count, true)) {
char *p;
PJSON top;
PJAR arp;
......@@ -4042,7 +4040,7 @@ char *jbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp;
} // endif bsp
if (!CheckMemory(g, initid, args, 2, false, true)) {
if (!CheckMemory(g, initid, args, 2, false, false, true)) {
int *x = NULL;
uint n = 2;
// PJSON jsp;
......@@ -4111,7 +4109,7 @@ char *jbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp;
} // endif bsp
if (!CheckMemory(g, initid, args, 1, false, true)) {
if (!CheckMemory(g, initid, args, 1, false, false, true)) {
int *x;
uint n = 1;
PJAR arp;
......@@ -4224,7 +4222,7 @@ char *jbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk;
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;
PJOB objp = new(g)JOBJECT;
......@@ -4281,7 +4279,7 @@ char *jbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk;
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;
for (uint i = 0; i < args->arg_count; i += 2)
......@@ -4335,7 +4333,7 @@ char *jbin_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp;
} // endif bsp
if (!CheckMemory(g, initid, args, 2, false, true)) {
if (!CheckMemory(g, initid, args, 2, false, true, true)) {
char *key;
PJOB jobp;
PJVAL jvp = MakeValue(g, args, 0, &top);
......@@ -4401,7 +4399,7 @@ char *jbin_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp;
} // endif bsp
if (!CheckMemory(g, initid, args, 1, false, true)) {
if (!CheckMemory(g, initid, args, 1, false, true, true)) {
char *key;
PJOB jobp;
PJVAL jvp = MakeValue(g, args, 0, &top);
......@@ -4458,7 +4456,7 @@ char *jbin_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result,
PBSON bsp = (PBSON)g->Xchk;
if (!bsp || bsp->Changed) {
if (!CheckMemory(g, initid, args, 1, false)) {
if (!CheckMemory(g, initid, args, 1, true, true)) {
char *p;
PJSON jsp;
PJVAL jvp = MakeValue(g, args, 0);
......@@ -4514,8 +4512,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,
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;
PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
bsp = (PBSON)g->Activityp;
......@@ -4523,19 +4525,17 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else if (initid->const_item)
g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
if (!g->Xchk) {
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 (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
return NULL;
goto fin;
} // endif jsp
} else
......@@ -4554,8 +4554,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (jsx->SetJpath(g, path, false)) {
PUSH_WARNING(g->Message);
*is_null = 1;
return NULL;
goto fin;
} // endif SetJpath
// Get the json tree
......@@ -4573,9 +4572,7 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Activityp = (PACTIVITY)bsp;
} // endif CheckMemory
fin:
fin:
if (!bsp) {
*is_null = 1;
*res_length = 0;
......@@ -4611,7 +4608,7 @@ char *jbin_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
return (char*)bsp;
} // endif bsp
if (!CheckMemory(g, initid, args, 2, false, true)) {
if (!CheckMemory(g, initid, args, 2, false, false, true)) {
PJVAL jvp;
PJSON jsp[2] = {NULL, NULL};
PGLOBAL gb = GetMemPtr(g, args, 0);
......@@ -4666,10 +4663,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,
unsigned long *res_length, char *is_null, char *error)
{
char *p, *path;
int w;
my_bool b = true;
PJSON jsp;
PJSNX jsx;
PJVAL jvp;
PBSON bsp = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr;
PGLOBAL gb = GetMemPtr(g, args, 0);
if (g->N) {
bsp = (PBSON)g->Activityp;
......@@ -4684,20 +4686,16 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
else
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 (CheckMemory(g, initid, args, 1, true, false, true)) {
PUSH_WARNING("CheckMemory error");
} else
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
return NULL;
goto fin;
} // endif jsp
} else
......@@ -4740,9 +4738,7 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Activityp = (PACTIVITY)bsp;
} // endif CheckMemory
fin:
fin:
if (!bsp) {
*is_null = 1;
*res_length = 0;
......@@ -4889,7 +4885,7 @@ char *jbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
// Keep result of constant function
g->Xchk = bsp;
fin:
fin:
if (!bsp) {
*res_length = 0;
*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