mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- Fix bug causing bnx base wrong after CheckMemory
Add negative array indexes starting from the last modified: storage/connect/bson.cpp modified: storage/connect/bsonudf.cpp modified: storage/connect/json.cpp
This commit is contained in:
@@ -1138,6 +1138,9 @@ PBVAL BJSON::GetArrayValue(PBVAL bap, int n)
|
||||
CheckType(bap, TYPE_JAR);
|
||||
int i = 0;
|
||||
|
||||
if (n < 0)
|
||||
n += GetArraySize(bap);
|
||||
|
||||
for (PBVAL bvp = GetArray(bap); bvp; bvp = GetNext(bvp), i++)
|
||||
if (i == n)
|
||||
return bvp;
|
||||
|
@@ -3707,6 +3707,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
|
||||
PUSH_WARNING("CheckMemory error");
|
||||
goto fin;
|
||||
} else {
|
||||
bnx.Reset();
|
||||
jvp = bnx.MakeValue(args, 0, true);
|
||||
|
||||
if (g->Mrr) { // First argument is a constant
|
||||
@@ -4052,6 +4053,7 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
|
||||
*is_null = 1;
|
||||
return 0.0;
|
||||
} else {
|
||||
bnx.Reset();
|
||||
jvp = bnx.MakeValue(args, 0);
|
||||
|
||||
if ((p = bnx.GetString(jvp))) {
|
||||
|
@@ -58,11 +58,19 @@ char *GetJsonNull(void);
|
||||
/***********************************************************************/
|
||||
/* IsNum: check whether this string is all digits. */
|
||||
/***********************************************************************/
|
||||
bool IsNum(PSZ s) {
|
||||
for (char* p = s; *p; p++)
|
||||
bool IsNum(PSZ s)
|
||||
{
|
||||
char* p = s;
|
||||
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
if (*p == ']')
|
||||
return false;
|
||||
else for (; *p; p++)
|
||||
if (*p == ']')
|
||||
break;
|
||||
else if (!isdigit(*p) || *p == '-')
|
||||
else if (!isdigit(*p))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -1257,6 +1265,8 @@ PJVAL JARRAY::GetArrayValue(int i)
|
||||
{
|
||||
if (Mvals && i >= 0 && i < Size)
|
||||
return Mvals[i];
|
||||
else if (Mvals && i < 0 && i >= -Size)
|
||||
return Mvals[Size + i];
|
||||
else
|
||||
return NULL;
|
||||
} // end of GetValue
|
||||
|
Reference in New Issue
Block a user