mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-30 22:17:13 +02:00
Fixed excpetion throwing in XML document to that generated corrupted messages because snprintf was used instead of vsnprintf.
Revised most of the XML plugin and cleaned code.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
#include "Module.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <stdarg.h>
|
||||
#include <cstdarg>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqrat.h>
|
||||
@ -33,8 +33,10 @@ void SqThrowF(CSStr str, ...)
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Write the requested contents
|
||||
if (snprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
strcpy(g_Buffer, "Unknown error has occurred");
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Throw the exception with the resulted message
|
||||
@ -48,17 +50,26 @@ CSStr FmtStr(CSStr str, ...)
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Write the requested contents
|
||||
if (snprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
g_Buffer[0] = 0; /* make sure the string is terminated */
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
g_Buffer[0] = 0; // Make sure the string is terminated
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Return the data from the buffer
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
StackGuard::StackGuard()
|
||||
: m_VM(_SqVM), m_Top(sq_gettop(m_VM))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
StackGuard::StackGuard(HSQUIRRELVM vm)
|
||||
: m_Top(sq_gettop(vm)), m_VM(vm)
|
||||
: m_VM(vm), m_Top(sq_gettop(vm))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@ -69,6 +80,15 @@ StackGuard::~StackGuard()
|
||||
sq_pop(m_VM, sq_gettop(m_VM) - m_Top);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DocumentRef::Validate() const
|
||||
{
|
||||
if (!m_Ptr)
|
||||
{
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger ParseResult::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
@ -82,14 +102,18 @@ void ParseResult::Validate() const
|
||||
{
|
||||
// Is the documen handle valid?
|
||||
if (!m_Doc)
|
||||
{
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ParseResult::Check() const
|
||||
{
|
||||
if (m_Result.status != status_ok)
|
||||
{
|
||||
STHROWF("XML parse error [%s]", m_Result.description());
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
Reference in New Issue
Block a user