Skip to content

Commit 1531321

Browse files
committed
MDEV-9993 - connect.json_udf_bin valgrind warnings
"result" may be uninitialized when json_set_item() is called directly.
1 parent fa10a65 commit 1531321

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

storage/connect/jsonudf.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,11 +3568,11 @@ my_bool json_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
35683568
return JsonInit(initid, args, message, true, reslen, memlen);
35693569
} // end of json_set_item_init
35703570

3571-
char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3572-
unsigned long *res_length, char *is_null, char *error)
3571+
static char *json_set_item_core(UDF_INIT *initid, UDF_ARGS *args, char *result,
3572+
unsigned long *res_length, char *is_null, char *error, int w)
35733573
{
35743574
char *p, *path, *str = NULL;
3575-
int w, rc;
3575+
int rc;
35763576
my_bool b = true;
35773577
PJSON jsp;
35783578
PJSNX jsx;
@@ -3586,13 +3586,6 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
35863586
} else if (initid->const_item)
35873587
g->N = 1;
35883588

3589-
if (!strcmp(result, "$insert"))
3590-
w = 1;
3591-
else if (!strcmp(result, "$update"))
3592-
w = 2;
3593-
else
3594-
w = 0;
3595-
35963589
// Save stack and allocation environment and prepare error return
35973590
if (g->jump_level == MAX_JUMP) {
35983591
PUSH_WARNING(MSG(TOO_MANY_JUMPS));
@@ -3671,7 +3664,13 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
36713664
*res_length = strlen(str);
36723665

36733666
return str;
3674-
} // end of json_set_item
3667+
} // end of json_set_item_core
3668+
3669+
char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3670+
unsigned long *res_length, char *is_null, char *error)
3671+
{
3672+
return json_set_item_core(initid, args, result, res_length, is_null, error, 0);
3673+
}
36753674

36763675
void json_set_item_deinit(UDF_INIT* initid)
36773676
{
@@ -3689,8 +3688,7 @@ my_bool json_insert_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
36893688
char *json_insert_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
36903689
unsigned long *res_length, char *is_null, char *p)
36913690
{
3692-
strcpy(result, "$insert");
3693-
return json_set_item(initid, args, result, res_length, is_null, p);
3691+
return json_set_item_core(initid, args, result, res_length, is_null, p, 1);
36943692
} // end of json_insert_item
36953693

36963694
void json_insert_item_deinit(UDF_INIT* initid)
@@ -3709,8 +3707,7 @@ my_bool json_update_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
37093707
char *json_update_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
37103708
unsigned long *res_length, char *is_null, char *p)
37113709
{
3712-
strcpy(result, "$update");
3713-
return json_set_item(initid, args, result, res_length, is_null, p);
3710+
return json_set_item_core(initid, args, result, res_length, is_null, p, 2);
37143711
} // end of json_update_item
37153712

37163713
void json_update_item_deinit(UDF_INIT* initid)

0 commit comments

Comments
 (0)