Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Alchemy/CodeChain/CodeChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ICCItemPtr CCodeChain::CreateDoubleIfPossible (const CString &sString)
ICCItemPtr CCodeChain::CreateIntegerIfPossible (const CString &sString)
{
bool bFailed;
int iValue = strToInt(sString, 0, &bFailed);
int iValue = strToCCInt(sString, 0, &bFailed);
if (bFailed)
return ICCItemPtr(CreateString(sString));
else
Expand Down Expand Up @@ -1047,7 +1047,7 @@ ICCItem *CCodeChain::EvaluateArgs (CEvalContext *pCtx, ICCItem *pArgs, const CSt
if (*pValidation == 'i')
{
bool bFailed;
int iValue = strToInt(pResult->GetStringValue(), 0, &bFailed);
int iValue = strToCCInt(pResult->GetStringValue(), 0, &bFailed);
if (bFailed)
{
pError = CreateError(LITERAL("Numeral expected"), pResult);
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/CodeChain/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ ICCItem *fnItemInfo (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)
else if (pValue->IsIdentifier())
{
bool bFailed;
int iResult = strToInt(pValue->GetStringValue(), 0, &bFailed);
int iResult = strToCCInt(pValue->GetStringValue(), 0, &bFailed);
if (!bFailed)
pResult = pCC->CreateInteger(iResult);
else
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/DirectXUtil/CTextBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ bool CRTFParser::ParseBlock (const STextFormatDesc &InitFormat, CString *retsErr
if (*sParam.GetASCIIZPointer() == '#')
dwRGB = (DWORD)strToCOLORREF(sParam);
else
dwRGB = (DWORD)strToInt(sParam, 0);
dwRGB = strToDWORD(sParam, 0);

Format.rgbColor = CG32bitPixel(GetRValue(dwRGB), GetGValue(dwRGB), GetBValue(dwRGB));
}
Expand Down
2 changes: 1 addition & 1 deletion Alchemy/Include/CodeChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class CCString : public ICCString
virtual ICCItem *Clone (CCodeChain *pCC) override;
virtual bool GetBinding (int *retiFrame, int *retiOffset) override;
virtual double GetDoubleValue (void) const override { return strToDouble(m_sValue, 0.0); }
virtual int GetIntegerValue (void) const override { return strToInt(m_sValue, 0); }
virtual int GetIntegerValue (void) const override { return strToCCInt(m_sValue, 0); }
virtual ICCItem *GetFunctionBinding (void) override { if (m_pBinding) return m_pBinding->Reference(); else return NULL; }
virtual CString GetStringValue (void) const override { return m_sValue; }
virtual CString Print (DWORD dwFlags = 0) const override;
Expand Down
22 changes: 18 additions & 4 deletions Alchemy/Include/KernelString.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,21 @@ inline char strLowerCaseAbsolute (char chChar) { if (!Kernel::g_bLowerCaseAbsolu
bool strNeedsEscapeCodes (const Kernel::CString &sString);

#define PARSE_THOUSAND_SEPARATOR 0x00000001
double strParseDouble (const char *pStart, double rNullResult, const char **retpEnd, bool *retbNullValue);
int strParseInt (const char *pStart, int iNullResult, DWORD dwFlags, const char **retpEnd = NULL, bool *retbNullValue = NULL);
inline int strParseInt (const char *pStart, int iNullResult, const char **retpEnd = NULL, bool *retbNullValue = NULL) { return Kernel::strParseInt(pStart, iNullResult, 0, retpEnd, retbNullValue); }
#define PARSE_ALLOW_OVERFLOW 0x00000002
#define PARSE_RAW_HEX 0x00000004
double strParseDouble (const char* pStart, double rNullResult, const char** retpEnd = NULL, bool* retbNullValue = NULL);
bool strParseWholeNumber (
const char* pStart,
DWORD dwFlags,
const char** retpEnd = NULL,
int* retiInt = NULL,
bool* retbIntOverflowed = NULL,
DWORD* retdwInt = NULL,
bool* retbDWORDOverflowed = NULL);
DWORD strParseDWORD (const char* pStart, DWORD dwNullResult, DWORD dwFlags, const char** retpEnd = NULL, bool* retbNullValue = NULL, bool* retbOverflowed = NULL);
inline DWORD strParseDWORD (const char* pStart, DWORD dwNullResult, const char** retpEnd = NULL, bool* retbNullValue = NULL, bool* retbOverflowed = NULL) { return Kernel::strParseDWORD(pStart, dwNullResult, 0, retpEnd, retbNullValue, retbOverflowed); }
int strParseInt (const char* pStart, int iNullResult, DWORD dwFlags, const char** retpEnd = NULL, bool* retbNullValue = NULL, bool* retbOverflowed = NULL);
inline int strParseInt (const char* pStart, int iNullResult, const char** retpEnd = NULL, bool* retbNullValue = NULL, bool* retbOverflowed = NULL) { return Kernel::strParseInt(pStart, iNullResult, 0, retpEnd, retbNullValue, retbOverflowed); }
int strParseIntOfBase (const char *pStart, int iBase, int iNullResult, const char **retpEnd = NULL, bool *retbNullValue = NULL);

void strParseWhitespace (const char *pPos, const char **retpPos);
Expand Down Expand Up @@ -281,7 +293,9 @@ double strToDouble (const Kernel::CString &sString, double rFailResult, bool *re
#define UNIT_STR_MASS_TONS CONSTLIT("t")
double strMassToDoubleTons (const Kernel::CString &sString, double rFailResult, bool *retbFailed = NULL);
Kernel::CString strToFilename (const Kernel::CString &sString);
int strToInt (const Kernel::CString &sString, int iFailResult, bool *retbFailed = NULL);
int strToInt (const Kernel::CString &sString, int iFailResult, bool *retbFailed = NULL, bool *retbOverflowed = NULL);
int strToCCInt (const Kernel::CString &sString, int iFailResult, bool *retbFailed = NULL);
DWORD strToDWORD (const Kernel::CString &sString, DWORD dwFailResult, bool *retbFailed = NULL, bool *retbOverflowed = NULL);
Kernel::CString strToLower (const Kernel::CString &sString);
Kernel::CString strToUpper (const Kernel::CString &sString);
Kernel::CString strToXMLText (const Kernel::CString &sString, bool bInBody = false);
Expand Down
4 changes: 4 additions & 0 deletions Alchemy/Include/XMLUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CXMLElement
bool FindAttributeBool (const CString &sName, bool *retbValue = NULL) const;
bool FindAttributeDouble (const CString &sName, double *retrValue = NULL) const;
bool FindAttributeInteger (const CString &sName, int *retiValue = NULL) const;
bool FindAttributeDWORD (const CString &sName, DWORD *retdwValue = NULL) const;
CString GetAttribute (const CString &sName) const;
CString GetAttribute (int iIndex) const { return m_Attributes[iIndex]; }
bool GetAttributeBool (const CString &sName) const;
Expand All @@ -106,6 +107,9 @@ class CXMLElement
int GetAttributeInteger (const CString &sName) const;
int GetAttributeIntegerDefault (const CString &sName, int iNull) const;
int GetAttributeIntegerBounded (const CString &sName, int iMin, int iMax = -1, int iNull = 0) const;
DWORD GetAttributeDWORD (const CString &sName) const;
DWORD GetAttributeDWORDDefault (const CString &sName, DWORD dwNull) const;
DWORD GetAttributeDWORDBounded (const CString &sName, DWORD dwMin, DWORD dwMax = 0xFFFF'FFFF, DWORD dwNull = 0) const;
bool GetAttributeIntegerRange (const CString &sName, int *retiLow, int *retiHigh, int iMin = 0, int iMax = -1, int iNullLow = 0, int iNullHigh = 0, bool bAllowInverted = false) const;
ALERROR GetAttributeIntegerList (const CString &sName, TArray<int> *pList) const;
ALERROR GetAttributeIntegerList (const CString &sName, TArray<DWORD> *pList) const;
Expand Down
5 changes: 3 additions & 2 deletions Alchemy/Kernel/CHTTPMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ ALERROR CHTTPMessage::InitFromStream (IReadStream &Stream, CString *retsError, b
return NOERROR;

// If we have a content length, then see if it is 0
// Content length is not permitted to be below 0 (RFC 9110)

CString sLength;
DWORD dwLength = 0;
if (FindHeader(CONSTLIT("Content-Length"), &sLength)
&& (dwLength = strToInt(sLength, 0)) == 0)
&& (dwLength = strToDWORD(sLength, 0)) == 0)
return NOERROR;

// Chunked encoding?
Expand Down Expand Up @@ -359,7 +360,7 @@ bool CHTTPMessage::ParseHTTPStartLine (IReadStream &Stream, CString *retsError)
if (*pPos == '\0')
return false;

m_dwStatusCode = strToInt(CString(pStart, (pPos - pStart)), 0);
m_dwStatusCode = strToDWORD(CString(pStart, (pPos - pStart)), 0);

// Next is the status message

Expand Down
17 changes: 15 additions & 2 deletions Alchemy/Kernel/CLargeSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,20 @@ bool CLargeSet::InitFromString (const CString &sValue, DWORD dwMaxValue, CString
{
const char *pEnd;
bool bFailed;
DWORD dwStartValue = (DWORD)strParseInt(pPos, 0, &pEnd, &bFailed);
bool bOverflowed;
DWORD dwStartValue = strParseDWORD(pPos, 0, &pEnd, &bFailed, &bOverflowed);
if (bFailed)
{
if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid number set format: %s"), sValue);
return false;
}

if (bOverflowed)
{
if (retsError) *retsError = strPatternSubst(CONSTLIT("Number set overflowed: %s"), sValue);
return false;
}

pPos = pEnd;
DWORD dwEndValue;

Expand All @@ -151,13 +158,19 @@ bool CLargeSet::InitFromString (const CString &sValue, DWORD dwMaxValue, CString
if (*pPos == '-')
{
pPos++;
dwEndValue = (DWORD)strParseInt(pPos, 0, &pEnd, &bFailed);
dwEndValue = strParseDWORD(pPos, 0, &pEnd, &bFailed, &bOverflowed);
if (bFailed)
{
if (retsError) *retsError = strPatternSubst(CONSTLIT("Invalid number set format: %s"), sValue);
return false;
}

if (bOverflowed)
{
if (retsError) *retsError = strPatternSubst(CONSTLIT("Number set overflowed: %s"), sValue);
return false;
}

pPos = pEnd;
}

Expand Down
Loading