shlwapi: Add size parameters to function that takes array arguments (Try 3)

Andrew Talbot Andrew.Talbot at talbotville.com
Wed Sep 27 13:27:37 CDT 2006


I'm never going to get the perfect title for this patch, but I hope the code
is good, this time.

-- Andy.
---
Changelog:
    shlwapi: Add size parameters to function that takes array arguments.

diff -urN a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c
--- a/dlls/shlwapi/string.c	2006-08-23 22:37:14.000000000 +0100
+++ b/dlls/shlwapi/string.c	2006-09-27 19:09:42.000000000 +0100
@@ -56,6 +56,9 @@
     } \
   } while (0)
 
+#define MAX_DECIMAL_BUFWLEN     8
+#define MAX_THOUSAND_BUFWLEN    8
+
 extern HMODULE SHLWAPI_hmlang;
 extern HINSTANCE shlwapi_hInstance;
 
@@ -66,7 +69,8 @@
 static HRESULT WINAPI _SHStrDupAW(LPCWSTR,LPSTR*);
 
 
-static void FillNumberFmt(NUMBERFMTW *fmt, WCHAR decimal_buffer[8], WCHAR thousand_buffer[8])
+static void FillNumberFmt(NUMBERFMTW *fmt, LPWSTR decimal_buffer, int decimal_bufwlen,
+                          LPWSTR thousand_buffer, int thousand_bufwlen)
 {
   WCHAR grouping[64];
   WCHAR *c;
@@ -74,11 +78,11 @@
   GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_ILZERO|LOCALE_RETURN_NUMBER, (LPWSTR)&fmt->LeadingZero, sizeof(fmt->LeadingZero)/sizeof(WCHAR));
   GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_INEGNUMBER|LOCALE_RETURN_NUMBER, (LPWSTR)&fmt->LeadingZero, sizeof(fmt->NegativeOrder)/sizeof(WCHAR));
   fmt->NumDigits = 0;
-  GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal_buffer, sizeof(decimal_buffer)/sizeof(WCHAR));
-  GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousand_buffer, sizeof(thousand_buffer)/sizeof(WCHAR));
+  GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimal_buffer, decimal_bufwlen);
+  GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousand_buffer, thousand_bufwlen);
   fmt->lpThousandSep = thousand_buffer;
   fmt->lpDecimalSep = decimal_buffer;
-  
+
   /* 
    * Converting grouping string to number as described on 
    * http://blogs.msdn.com/oldnewthing/archive/2006/04/18/578251.aspx
@@ -109,13 +113,14 @@
 static int FormatInt(LONGLONG qdwValue, LPWSTR pszBuf, int cchBuf)
 {
   NUMBERFMTW fmt;
-  WCHAR decimal[8], thousand[8];
+  WCHAR decimal[MAX_DECIMAL_BUFWLEN], thousand[MAX_THOUSAND_BUFWLEN];
   WCHAR buf[24];
   WCHAR *c;
   BOOL neg = (qdwValue < 0);
 
-  FillNumberFmt(&fmt, decimal, thousand);  
-    
+  FillNumberFmt(&fmt, decimal, sizeof decimal / sizeof (WCHAR),
+                thousand, sizeof thousand / sizeof (WCHAR));
+
   c = &buf[24];
   *(--c) = 0;
   do
@@ -143,11 +148,12 @@
   static const WCHAR flfmt[] = {'%','f',0};
   WCHAR buf[64];
   NUMBERFMTW fmt;
-  WCHAR decimal[8], thousand[8];
-  
+  WCHAR decimal[MAX_DECIMAL_BUFWLEN], thousand[MAX_THOUSAND_BUFWLEN];
+
   snprintfW(buf, 64, flfmt, value);
 
-  FillNumberFmt(&fmt, decimal, thousand);  
+  FillNumberFmt(&fmt, decimal, sizeof decimal / sizeof (WCHAR),
+                 thousand, sizeof thousand / sizeof (WCHAR));
   fmt.NumDigits = decimals;
   return GetNumberFormatW(LOCALE_USER_DEFAULT, 0, buf, &fmt, pszBuf, cchBuf);
 }



More information about the wine-patches mailing list