From e2dd624761180dccdb2a542623964c8cd4fdb721 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2010 14:30:28 +0000 Subject: [PATCH] Fix handling of asterisks in wxPrintf() implementation. Count the number of asterisks before modifying the string we use to do this, otherwise we were off by one for the format specifications containing two of them. This really fixes the handling of asterisks (used for width/precision) in wxPrintf() format string, it wasn't done correctly by r60120 but now VsnprintfTestCase::Asterisk() test does pass. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65689 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/private/wxprintf.h | 62 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/include/wx/private/wxprintf.h b/include/wx/private/wxprintf.h index 7b7b290fd6..f60d9e8ea9 100644 --- a/include/wx/private/wxprintf.h +++ b/include/wx/private/wxprintf.h @@ -831,43 +831,49 @@ struct wxPrintfConvSpecParser // special handling for specifications including asterisks: we need // to reserve an extra slot (or two if asterisks were used for both // width and precision) in specs array in this case - for ( const char *f = strchr(spec->m_szFlags, '*'); - f; - f = strchr(f + 1, '*') ) + if ( const char *f = strchr(spec->m_szFlags, '*') ) { - if ( nargs++ == wxMAX_SVNPRINTF_ARGUMENTS ) - break; + unsigned numAsterisks = 1; + if ( strchr(++f, '*') ) + numAsterisks++; - // TODO: we need to support specifiers of the form "%2$*1$s" - // (this is the same as "%*s") as if any positional arguments - // are used all asterisks must be positional as well but this - // requires a lot of changes in this code (basically we'd need - // to rewrite Parse() to return "*" and conversion itself as - // separate entries) - if ( posarg_present ) + for ( unsigned n = 0; n < numAsterisks; n++ ) { - wxFAIL_MSG - ( - wxString::Format + if ( nargs++ == wxMAX_SVNPRINTF_ARGUMENTS ) + break; + + // TODO: we need to support specifiers of the form "%2$*1$s" + // (this is the same as "%*s") as if any positional arguments + // are used all asterisks must be positional as well but this + // requires a lot of changes in this code (basically we'd need + // to rewrite Parse() to return "*" and conversion itself as + // separate entries) + if ( posarg_present ) + { + wxFAIL_MSG ( - "Format string \"%s\" uses both positional " - "parameters and '*' but this is not currently " - "supported by this implementation, sorry.", - fmt - ) - ); - } + wxString::Format + ( + "Format string \"%s\" uses both positional " + "parameters and '*' but this is not currently " + "supported by this implementation, sorry.", + fmt + ) + ); + } - specs[nargs] = *spec; + specs[nargs] = *spec; - // make an entry for '*' and point to it from pspec - spec->Init(); - spec->m_type = wxPAT_STAR; - pspec[nargs - 1] = spec; + // make an entry for '*' and point to it from pspec + spec->Init(); + spec->m_type = wxPAT_STAR; + pspec[nargs - 1] = spec; - spec = &specs[nargs]; + spec = &specs[nargs]; + } } + // check if this is a positional or normal argument if ( spec->m_pos > 0 ) { -- 2.45.2