int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc; char *argv[64]; // max 64 command line arguments CrashLog::InitialiseCrashLog(); #if defined(UNICODE) /* Check if a win9x user started the win32 version */ if (HasBit(GetVersion(), 31)) usererror("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again."); #endif /* Convert the command line to UTF-8. We need a dedicated buffer * for this because argv[] points into this buffer and this needs to * be available between subsequent calls to FS2OTTD(). */ char *cmdline = stredup(FS2OTTD(GetCommandLine())); #if defined(_DEBUG) CreateConsole(); #endif _set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox /* setup random seed to something quite random */ SetRandomSeed(GetTickCount()); argc = ParseCommandLine(cmdline, argv, lengthof(argv)); /* Make sure our arguments contain only valid UTF-8 characters. */ for (int i = 0; i < argc; i++) ValidateString(argv[i]); openttd_main(argc, argv); free(cmdline); return 0; }
bool ValidateString(char *szString, ValidationOption eOption) { // validate in a StdStrBuf. Does one alloc and copy :( StdStrBuf buf; buf.Copy(szString); bool fInvalid = ValidateString(buf, eOption); return fInvalid; }
/* * Prints out the given xml element etc. * * \todo Make the destination of the output changeable (defaults to stdout) * * \param currentIndentLevel the indent level of the message * \param EOL will it print end of line character or not * \param the XML element itself * */ void XMLOutputter(const int currentIndentLevel, int EOL, const char *message) { if(ValidateString(message)) { int indent = 0; for( ; indent < currentIndentLevel && prevEOL; ++indent) { fprintf(logFile, " "); // \todo make configurable? } prevEOL = EOL; if(EOL) { fprintf(logFile, "%s\n", message); } else { fprintf(logFile, "%s", message); } fflush(logFile); } else { fprintf(logFile, "Error: Tried to output invalid string!"); } SDL_free((char *)message); }
bool ValidateString(char *szString, ValidationOption eOption, size_t iMaxSize) { // validate in a StdStrBuf. Does one alloc and copy :( StdStrBuf buf; buf.Copy(szString); bool fInvalid = ValidateString(buf, eOption); if (fInvalid) SCopy(buf.getData(), szString, iMaxSize); return fInvalid; }
bool Squirrel::CallStringMethodStrdup(HSQOBJECT instance, const char *method_name, const char **res, int suspend) { HSQOBJECT ret; if (!this->CallMethod(instance, method_name, &ret, suspend)) return false; if (ret._type != OT_STRING) return false; *res = strdup(ObjectToString(&ret)); ValidateString(*res); return true; }
int CDECL main(int argc, char *argv[]) { SetRandomSeed(time(NULL)); /* Make sure our arguments contain only valid UTF-8 characters. */ for (int i = 0; i < argc; i++) ValidateString(argv[i]); return openttd_main(argc, argv); }
bool Format::ToInteger(const char *psz, int base, int *pint) { if (!ValidateString(psz, base)) { return false; } *pint = 0; long l = strtol(psz, (char **)NULL, base); *pint = (int)l; return true; }
bool Format::ToDword(const char *psz, int base, dword *pdw) { if (!ValidateString(psz, base)) { return false; } *pdw = 0; long long ll = strtoll(psz, (char **)NULL, base); *pdw = (dword)ll; return true; }
CXmlItem::CXmlItem(CXmlItem* pParent, const CString& sName, const CString& sValue, XI_TYPE nType) : m_pParent(pParent), m_pSibling(NULL), m_sName(sName), m_sValue(sValue), m_nType(nType) { ValidateString(m_sValue); }
// sometimes the string in prop is invalid, causing unexpected crashes LPCTSTR CMAPIEx::GetValidMVString(SPropValue& prop, int nIndex) { return ValidateString(prop.Value.MVSZ.LPPSZ[nIndex]); }
LPCTSTR CMAPIEx::GetValidString(SPropValue& prop) { return ValidateString(prop.Value.LPSZ); }
void CXmlItem::SetValue(const CString& sValue) { m_sValue = sValue; ValidateString(m_sValue); }