1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01:00

Make it possible for the Buffer wrapper to detect the length of a raw string if the requested length is negative.

This commit is contained in:
Sandu Liviu Catalin 2017-06-16 02:24:19 +03:00
parent f048950d20
commit 957ba97a33
2 changed files with 21 additions and 2 deletions

View File

@ -218,10 +218,29 @@ Object SqBuffer::ReadString()
}
// ------------------------------------------------------------------------------------------------
Object SqBuffer::ReadRawString(Uint32 len)
Object SqBuffer::ReadRawString(SQInteger length)
{
// Validate the managed buffer reference
ValidateDeeper();
// Start with a length of zero
Uint32 len = 0;
// Should we Identify the string length ourselves?
if (length < 0)
{
// Grab the buffer range to search for
CCStr ptr = &m_Buffer->Cursor(), itr = ptr, end = m_Buffer->End();
// Attempt to look for a string terminator
while (itr != end && *itr != '\0')
{
++itr;
}
// If nothing was found, consider the remaining buffer part of the requested string
len = static_cast< Uint32 >(ptr - itr);
}
else
{
len = ConvTo< Uint32 >::From(length);
}
// Validate the obtained length
if ((m_Buffer->Position() + len) > m_Buffer->Capacity())
{

View File

@ -779,7 +779,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Read a raw string from the buffer.
*/
Object ReadRawString(Uint32 len);
Object ReadRawString(SQInteger length);
/* --------------------------------------------------------------------------------------------
* Read a AABB from the buffer.