cryptui: Fix a string resource so its format placeholders can be reordered.

Francois Gouget fgouget at free.fr
Sat Nov 19 08:10:16 CST 2011


---
 dlls/cryptui/cryptui.rc |    2 +-
 dlls/cryptui/main.c     |   20 +++++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/dlls/cryptui/cryptui.rc b/dlls/cryptui/cryptui.rc
index bbac4f4..5f35f0c 100644
--- a/dlls/cryptui/cryptui.rc
+++ b/dlls/cryptui/cryptui.rc
@@ -55,7 +55,7 @@ STRINGTABLE
     IDS_FIELD_VALID_TO "Valid to"
     IDS_FIELD_SUBJECT "Subject"
     IDS_FIELD_PUBLIC_KEY "Public key"
-    IDS_FIELD_PUBLIC_KEY_FORMAT "%s (%d bits)"
+    IDS_FIELD_PUBLIC_KEY_FORMAT "%1 (%2!d! bits)"
     IDS_PROP_HASH "SHA1 hash"
     IDS_PROP_ENHKEY_USAGE "Enhanced key usage (property)"
     IDS_PROP_FRIENDLY_NAME "Friendly name"
diff --git a/dlls/cryptui/main.c b/dlls/cryptui/main.c
index 5c8fd27..387b6c6 100644
--- a/dlls/cryptui/main.c
+++ b/dlls/cryptui/main.c
@@ -2704,6 +2704,8 @@ static WCHAR *field_format_public_key(PCCERT_CONTEXT cert)
         if (LoadStringW(hInstance, IDS_FIELD_PUBLIC_KEY_FORMAT, fmt,
          sizeof(fmt) / sizeof(fmt[0])))
         {
+            DWORD len;
+
             /* Allocate the output buffer.  Use the number of bytes in the
              * public key as a conservative (high) estimate for the number of
              * digits in its output.
@@ -2713,14 +2715,18 @@ static WCHAR *field_format_public_key(PCCERT_CONTEXT cert)
              * good idea, but as this isn't a sentence fragment, it shouldn't
              * be word-order dependent.
              */
-            buf = HeapAlloc(GetProcessHeap(), 0,
-             (strlenW(fmt) + strlenW(oidInfo->pwszName) +
-             cert->pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData * 8)
-             * sizeof(WCHAR));
+            len = strlenW(fmt) + strlenW(oidInfo->pwszName) +
+                cert->pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData * 8;
+            buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*buf));
             if (buf)
-                sprintfW(buf, fmt, oidInfo->pwszName,
-                 CertGetPublicKeyLength(X509_ASN_ENCODING,
-                  &cert->pCertInfo->SubjectPublicKeyInfo));
+            {
+                DWORD_PTR args[2];
+                args[0] = (DWORD_PTR)oidInfo->pwszName;
+                args[1] = CertGetPublicKeyLength(X509_ASN_ENCODING,
+                              &cert->pCertInfo->SubjectPublicKeyInfo);
+                FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
+                               fmt, 0, 0, buf, len, (__ms_va_list*)args);
+            }
         }
     }
     return buf;
-- 
1.7.7.1



More information about the wine-patches mailing list