void wxVLogScript(const wxChar *szFormat, va_list argptr)
{
    static wxChar s_szBuf[8192];

    if (sysLogger::logLevel >= LOG_SQL)
    {
        wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
        wxLog::OnLog(wxLOG_Script, s_szBuf, time(NULL));
    }
}
// IMPLEMENT_LOG_FUNCTION(Sql) from wx../common/log.c
void wxVLogQuietError(const wxChar *szFormat, va_list argptr)
{
    static wxChar s_szBuf[8192];

    if (sysLogger::logLevel >= LOG_ERRORS)
    {
        wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
        wxLog::OnLog(wxLOG_QuietError, s_szBuf, time(NULL));

    }
}
Пример #3
0
static int
wxUnsafeSnprintf(T *buf, size_t len, const wxChar *fmt, ...)
{
    va_list args;
    va_start(args, fmt);

    int rc = wxVsnprintf(buf, len, fmt, args);

    va_end(args);

    return rc;
}
Пример #4
0
// Miscellaneous() test case helper:
void VsnprintfTestCase::DoMisc(
        int expectedLen,
        const wxString& expectedString,
        size_t max,
        const wxChar *format, ...)
{
    const size_t BUFSIZE = MAX_TEST_LEN - 1;
    size_t i;
    static int count = 0;

    wxASSERT(max <= BUFSIZE);

    for (i = 0; i < BUFSIZE; i++)
        buf[i] = '*';
    buf[BUFSIZE] = 0;

    va_list ap;
    va_start(ap, format);

    int n = wxVsnprintf(buf, max, format, ap);

    va_end(ap);

    // Prepare messages so that it is possible to see from the error which
    // test was running.
    wxString errStr, overflowStr;
    errStr << wxT("No.: ") << ++count << wxT(", expected: ") << expectedLen
           << wxT(" '") << expectedString << wxT("', result: ");
    overflowStr << errStr << wxT("buffer overflow");
    errStr << n << wxT(" '") << buf << wxT("'");

    // turn them into std::strings
    std::string errMsg(errStr.mb_str());
    std::string overflowMsg(overflowStr.mb_str());

    CPPUNIT_ASSERT_MESSAGE(errMsg,
            (expectedLen == -1 && size_t(n) >= max) || expectedLen == n);

    CPPUNIT_ASSERT_MESSAGE(errMsg, expectedString == buf);

    for (i = max; i < BUFSIZE; i++)
        CPPUNIT_ASSERT_MESSAGE(overflowMsg, buf[i] == '*');
}
Пример #5
0
// returns the length of the formatted string, in characters (wxChars).
static
#ifndef __linux__
    __ri
#endif
        uint
        format_that_unicode_mess(CharBufferType &buffer, uint writepos, const wxChar *fmt, va_list argptr)
{
    va_list args;
    while (true) {
        int size = buffer.GetLength() / sizeof(wxChar);

        va_copy(args, argptr);
        int len = wxVsnprintf((wxChar *)buffer.GetPtr(writepos * sizeof(wxChar)), size - writepos, fmt, args);
        va_end(args);

        // some implementations of vsnprintf() don't NUL terminate
        // the string if there is not enough space for it so
        // always do it manually
        ((wxChar *)buffer.GetPtr())[size - 1] = L'\0';

        if (size >= MaxFormattedStringLength)
            return size - 1;

        // vsnprintf() may return either -1 (traditional Unix behavior) or the
        // total number of characters which would have been written if the
        // buffer were large enough (newer standards such as Unix98)

        if (len < 0)
            len = size + (size / 4);

        len += writepos;
        if (len < size)
            return len;
        buffer.Resize((len + 128) * sizeof(wxChar));
    };

    // performing an assertion or log of a truncated string is unsafe, so let's not; even
    // though it'd be kinda nice if we did.

    pxAssume(false);
    return 0; // unreachable.
}
Пример #6
0
// This function is used to output the dump
void wxDebugContext::OutputDumpLine(const wxChar *szFormat, ...)
{
    // a buffer of 2048 bytes should be long enough for a file name
    // and a class name
    wxChar buf[2048];
    int count;
    va_list argptr;
    va_start(argptr, szFormat);
    buf[WXSIZEOF(buf)-1] = wxT('\0');

    // keep 3 bytes for a \r\n\0
    count = wxVsnprintf(buf, WXSIZEOF(buf)-3, szFormat, argptr);

    if ( count < 0 )
        count = WXSIZEOF(buf)-3;
    buf[count]=wxT('\r');
    buf[count+1]=wxT('\n');
    buf[count+2]=wxT('\0');

    wxMessageOutputDebug dbgout;
    dbgout.Printf(buf);
}