always NUL-terminate the m_szFlags buffer; add test for %*s case

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58994 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-02-18 15:49:09 +00:00
parent 2e70f5211e
commit 4a7f0351fc
2 changed files with 18 additions and 3 deletions

View File

@@ -565,6 +565,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format)
break;
case wxT('c'):
m_szFlags[flagofs++] = char(ch);
m_szFlags[flagofs] = '\0';
if (ilen == -1)
{
// in Unicode mode %hc == ANSI character
@@ -591,6 +593,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format)
break;
case wxT('s'):
m_szFlags[flagofs++] = char(ch);
m_szFlags[flagofs] = '\0';
if (ilen == -1)
{
// Unicode mode wx extension: we'll let %hs mean non-Unicode
@@ -615,6 +619,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format)
break;
case wxT('n'):
m_szFlags[flagofs++] = char(ch);
m_szFlags[flagofs] = '\0';
if (ilen == 0)
m_type = wxPAT_NINT;
else if (ilen == -1)
@@ -671,7 +677,7 @@ void wxPrintfConvSpec::ReplaceAsteriskWith(int width)
bool wxPrintfConvSpec::LoadArg(wxPrintfArg *p, va_list &argptr)
{
// did the '*' width/precision specifier was used ?
// was the '*' width/precision specifier used ?
if (m_nMaxWidth == -1)
{
// take the maxwidth specifier from the stack

View File

@@ -40,6 +40,11 @@ int r;
#define ASSERT_STR_EQUAL( a, b ) \
CPPUNIT_ASSERT_EQUAL( wxString(a), wxString(b) );
#define CMP6(expected, x, y, z, w, t) \
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w, t); \
CPPUNIT_ASSERT( r > 0 ); \
ASSERT_STR_EQUAL( wxT(expected), buf );
#define CMP5(expected, x, y, z, w) \
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w); \
CPPUNIT_ASSERT( r > 0 ); \
@@ -290,6 +295,10 @@ void VsnprintfTestCase::Asterisk()
CMP5("0.1", "%*.*f", 3, 1, 0.123);
CMP4("%0.002", "%%%.*f", 3, 0.0023456789);
CMP4(" a", "%*c", 8, 'a');
CMP4(" four", "%*s", 8, "four");
CMP6(" four four", "%*s %*s", 8, "four", 6, "four");
}
void VsnprintfTestCase::Percent()