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:
@@ -565,6 +565,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxT('c'):
|
case wxT('c'):
|
||||||
|
m_szFlags[flagofs++] = char(ch);
|
||||||
|
m_szFlags[flagofs] = '\0';
|
||||||
if (ilen == -1)
|
if (ilen == -1)
|
||||||
{
|
{
|
||||||
// in Unicode mode %hc == ANSI character
|
// in Unicode mode %hc == ANSI character
|
||||||
@@ -591,6 +593,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxT('s'):
|
case wxT('s'):
|
||||||
|
m_szFlags[flagofs++] = char(ch);
|
||||||
|
m_szFlags[flagofs] = '\0';
|
||||||
if (ilen == -1)
|
if (ilen == -1)
|
||||||
{
|
{
|
||||||
// Unicode mode wx extension: we'll let %hs mean non-Unicode
|
// Unicode mode wx extension: we'll let %hs mean non-Unicode
|
||||||
@@ -615,6 +619,8 @@ bool wxPrintfConvSpec::Parse(const wxChar *format)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxT('n'):
|
case wxT('n'):
|
||||||
|
m_szFlags[flagofs++] = char(ch);
|
||||||
|
m_szFlags[flagofs] = '\0';
|
||||||
if (ilen == 0)
|
if (ilen == 0)
|
||||||
m_type = wxPAT_NINT;
|
m_type = wxPAT_NINT;
|
||||||
else if (ilen == -1)
|
else if (ilen == -1)
|
||||||
@@ -671,7 +677,7 @@ void wxPrintfConvSpec::ReplaceAsteriskWith(int width)
|
|||||||
|
|
||||||
bool wxPrintfConvSpec::LoadArg(wxPrintfArg *p, va_list &argptr)
|
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)
|
if (m_nMaxWidth == -1)
|
||||||
{
|
{
|
||||||
// take the maxwidth specifier from the stack
|
// take the maxwidth specifier from the stack
|
||||||
|
@@ -40,6 +40,11 @@ int r;
|
|||||||
#define ASSERT_STR_EQUAL( a, b ) \
|
#define ASSERT_STR_EQUAL( a, b ) \
|
||||||
CPPUNIT_ASSERT_EQUAL( wxString(a), wxString(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) \
|
#define CMP5(expected, x, y, z, w) \
|
||||||
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w); \
|
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w); \
|
||||||
CPPUNIT_ASSERT( r > 0 ); \
|
CPPUNIT_ASSERT( r > 0 ); \
|
||||||
@@ -290,6 +295,10 @@ void VsnprintfTestCase::Asterisk()
|
|||||||
CMP5("0.1", "%*.*f", 3, 1, 0.123);
|
CMP5("0.1", "%*.*f", 3, 1, 0.123);
|
||||||
|
|
||||||
CMP4("%0.002", "%%%.*f", 3, 0.0023456789);
|
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()
|
void VsnprintfTestCase::Percent()
|
||||||
|
Reference in New Issue
Block a user