1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Validate sub-str range.

This commit is contained in:
Sandu Liviu Catalin 2022-06-13 04:00:41 +03:00
parent c4b9b4c0a5
commit a1a71ee031

View File

@ -117,6 +117,11 @@ struct RxMatch
*/ */
[[nodiscard]] LightObj SubStr(StackStrF & str) const [[nodiscard]] LightObj SubStr(StackStrF & str) const
{ {
if ((mOffset + mLength) > str.mLen)
{
STHROWF("Rx: Match is outside the range of the specified string.");
}
// Return the sub-string
return LightObj{str.mPtr + mOffset, mLength}; return LightObj{str.mPtr + mOffset, mLength};
} }
}; };
@ -371,6 +376,12 @@ struct RxMatches
[[nodiscard]] LightObj SubStr(SQInteger i, StackStrF & str) const [[nodiscard]] LightObj SubStr(SQInteger i, StackStrF & str) const
{ {
const RxMatch & m = ValidIdx(i)[i]; const RxMatch & m = ValidIdx(i)[i];
// Check if match is within range
if ((m.mOffset + m.mLength) > str.mLen)
{
STHROWF("Rx: Match is outside the range of the specified string.");
}
// Return the sub-string
return LightObj{str.mPtr + m.mOffset, m.mLength}; return LightObj{str.mPtr + m.mOffset, m.mLength};
} }
}; };