]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix handling of asterisks in wxPrintf() implementation.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 30 Sep 2010 14:30:28 +0000 (14:30 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 30 Sep 2010 14:30:28 +0000 (14:30 +0000)
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

index 7b7b290fd647c43130211bda92e2e5ebcca3e487..f60d9e8ea99da61c68647e87cf3e359ffcf8ef60 100644 (file)
@@ -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 )
             {