mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Validate sub-str range.
This commit is contained in:
parent
c4b9b4c0a5
commit
a1a71ee031
@ -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};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user