- fix changing time format garbles the clock output

- patch by Carlo Bramix and Alwyn Tar
- fix potential buffer overflows by me
- bug 2437

svn path=/trunk/; revision=33335
This commit is contained in:
Johannes Anderwald 2008-05-06 20:51:07 +00:00
parent 7325a8a281
commit 2799b51019
5 changed files with 64 additions and 52 deletions

View file

@ -59,8 +59,8 @@ LPTSTR
FindDateSep(const TCHAR *szSourceStr)
{
LPTSTR pszFoundSep;
INT nDateCompCount=0;
INT nDateSepCount=0;
UINT nDateCompCount=0;
UINT nDateSepCount=0;
pszFoundSep = (LPTSTR)malloc(MAX_SAMPLES_STR_SIZE * sizeof(TCHAR));
@ -418,7 +418,7 @@ SetMaxDate(HWND hwndDlg, LCID lcid)
SetCalendarInfo(lcid,
CAL_GREGORIAN,
48 , /* CAL_ITWODIGITYEARMAX */
(LPCTSTR)&szMaxDateVal);
(LPCTSTR)szMaxDateVal);
}
/* Get max date value from registry set */

View file

@ -67,7 +67,7 @@ LocalesEnumProc(LPTSTR lpLocale)
}
else
{
GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang));
GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)/sizeof(TCHAR));
}
if (bNoShow == FALSE)
@ -135,7 +135,7 @@ CreateLanguagesList(HWND hwnd)
/* Select current locale */
/* or should it be System and not user? */
GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel));
GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)/sizeof(TCHAR));
SendMessage(hList,
CB_SELECTSTRING,
@ -160,14 +160,14 @@ SetNewLocale(LCID lcid)
TCHAR ACPPage[9];
TCHAR OEMPage[9];
ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, (WORD*)OEMPage, sizeof(OEMPage));
ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, OEMPage, sizeof(OEMPage)/sizeof(TCHAR));
if (ret == 0)
{
MessageBox(NULL, _T("Problem reading OEM code page"), _T("Big Problem"), MB_OK);
return;
}
GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, (WORD*)ACPPage, sizeof(ACPPage));
ret = GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, ACPPage, sizeof(ACPPage)/sizeof(TCHAR));
if (ret == 0)
{
MessageBox(NULL, _T("Problem reading ANSI code page"), _T("Big Problem"), MB_OK);
@ -305,7 +305,7 @@ VerifyUnattendLCID(HWND hwndDlg)
continue;
}
if (lResult == (LCID)UnattendLCID)
if (lResult == (LRESULT)UnattendLCID)
{
SendMessage(hList, CB_SETCURSEL, (WPARAM)lIndex, (LPARAM)0);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);

View file

@ -47,7 +47,7 @@ InsSpacesFmt(LPCTSTR szSourceStr, LPCTSTR szFmtStr)
LPTSTR pszDestStr;
LPTSTR pszTempStr;
TCHAR szFmtVal[255];
INT nFmtCount = 0;
UINT nFmtCount = 0;
INT nValCount = 0;
INT nLastVal = 0;
INT nSpaceOffset = 0;
@ -124,10 +124,10 @@ ReplaceSubStr(LPCTSTR szSourceStr,
LPCTSTR szTempl)
{
LPTSTR szDestStr;
INT nCharCnt;
INT nSubStrCnt;
INT nDestStrCnt;
INT nFirstCharCnt;
UINT nCharCnt;
UINT nSubStrCnt;
UINT nDestStrCnt;
UINT nFirstCharCnt;
szDestStr = (LPTSTR)malloc(MAX_SAMPLES_STR_SIZE * sizeof(TCHAR));

View file

@ -64,7 +64,7 @@ SortEnumProc(LPTSTR lpLocale)
if ((LANGIDFROMLCID(lcid) == LANGIDFROMLCID(userLcid)) &&
(SORTIDFROMLCID(lcid) != SORTIDFROMLCID(userLcid)))
{
GetLocaleInfo(lcid, LOCALE_SSORTNAME, lang, sizeof(lang));
GetLocaleInfo(lcid, LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hWndSortList,
CB_ADDSTRING,
@ -94,7 +94,7 @@ CreateSortList(HWND hwnd, LCID lcid)
{
/* Add traditional sorting */
GetLocaleInfo(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH),
LOCALE_SSORTNAME, lang, sizeof(lang));
LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hwnd,
CB_ADDSTRING,
@ -108,7 +108,7 @@ CreateSortList(HWND hwnd, LCID lcid)
/* Add modern sorting */
GetLocaleInfo(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN),
LOCALE_SSORTNAME, lang, sizeof(lang));
LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hwnd,
CB_ADDSTRING,
@ -124,7 +124,7 @@ CreateSortList(HWND hwnd, LCID lcid)
{
userLcid = lcid;
GetLocaleInfo(lcid & 0xFFFF, LOCALE_SSORTNAME, lang, sizeof(lang));
GetLocaleInfo(lcid & 0xFFFF, LOCALE_SSORTNAME, lang, sizeof(lang)/sizeof(TCHAR));
index = SendMessage(hWndSortList,
CB_ADDSTRING,

View file

@ -27,6 +27,7 @@
#include <commctrl.h>
#include <cpl.h>
#include <tchar.h>
#include <malloc.h>
#include "intl.h"
#include "resource.h"
@ -54,6 +55,36 @@ UpdateTimeSample(HWND hWnd, LCID lcid)
}
static VOID
GetSelectedComboEntry(HWND hwndDlg, DWORD dwIdc, TCHAR *Buffer, UINT uSize)
{
int nIndex;
HWND hChildWnd;
/* get handle to time format control */
hChildWnd = GetDlgItem(hwndDlg, dwIdc);
/* Get index to selected time format */
nIndex = SendMessage(hChildWnd, CB_GETCURSEL, 0, 0);
if (nIndex == CB_ERR)
/* no selection? get content of the edit control */
SendMessage(hChildWnd, WM_GETTEXT, uSize, (LPARAM)Buffer);
else {
LPTSTR tmp;
UINT uReqSize;
/* get requested size, including the null terminator;
* it shouldn't be required because the previous CB_LIMITTEXT,
* but it would be better to check it anyways */
uReqSize = SendMessage(hChildWnd, CB_GETLBTEXTLEN, (WPARAM)nIndex, 0) + 1;
/* allocate enought space, to be more safe */
tmp = (LPTSTR)_alloca(uReqSize*sizeof(TCHAR));
/* get selected time format text */
SendMessage(hChildWnd, CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)tmp);
/* finally, copy the result into the output */
_tcsncpy(Buffer, tmp, uSize);
}
}
/* Property page dialog callback */
INT_PTR CALLBACK
TimePageProc(HWND hwndDlg,
@ -86,7 +117,7 @@ TimePageProc(HWND hwndDlg,
hwndEnum = GetDlgItem(hwndDlg, IDC_TIMEFORMAT);
EnumTimeFormats(TimeFormatEnumProc, pGlobalData->lcid, 0);
GetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer, 80);
GetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer, sizeof(Buffer)/sizeof(TCHAR));
SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
CB_SELECTSTRING,
-1,
@ -95,7 +126,7 @@ TimePageProc(HWND hwndDlg,
/* Get the time separator (max. 4 characters) */
SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
CB_LIMITTEXT, 4, 0);
GetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer, 80);
GetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer, sizeof(Buffer)/sizeof(TCHAR));
SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
CB_ADDSTRING,
0,
@ -170,49 +201,30 @@ TimePageProc(HWND hwndDlg,
if (lpnm->code == (UINT)PSN_APPLY)
{
TCHAR Buffer[80];
int nIndex;
/* get selected/typed time format text */
GetSelectedComboEntry(hwndDlg, IDC_TIMEFORMAT, Buffer, sizeof(Buffer)/sizeof(TCHAR));
/* Set time format */
nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
CB_GETCURSEL, 0, 0);
SendMessage(GetDlgItem(hwndDlg, IDC_TIMEFORMAT),
CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
SetLocaleInfo(pGlobalData->lcid, LOCALE_STIMEFORMAT, Buffer);
/* get selected/typed time separator text */
GetSelectedComboEntry(hwndDlg, IDC_TIMESEPARATOR, Buffer, sizeof(Buffer)/sizeof(TCHAR));
/* Set time separator */
nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
CB_GETCURSEL, 0, 0);
SendMessage(GetDlgItem(hwndDlg, IDC_TIMESEPARATOR),
CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
SetLocaleInfo(pGlobalData->lcid, LOCALE_STIME, Buffer);
/* get selected/typed AM symbol text */
GetSelectedComboEntry(hwndDlg, IDC_TIMEAMSYMBOL, Buffer, sizeof(Buffer)/sizeof(TCHAR));
/* Set the AM symbol */
nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
CB_GETCURSEL, 0, 0);
if (nIndex != CB_ERR)
{
SendMessage(GetDlgItem(hwndDlg, IDC_TIMEAMSYMBOL),
CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, Buffer);
}
else
{
SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, _T(""));
}
SetLocaleInfo(pGlobalData->lcid, LOCALE_S1159, Buffer);
/* get selected/typed PM symbol text */
GetSelectedComboEntry(hwndDlg, IDC_TIMEPMSYMBOL, Buffer, sizeof(Buffer)/sizeof(TCHAR));
/* Set the PM symbol */
nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
CB_GETCURSEL, 0, 0);
if (nIndex != CB_ERR)
{
SendMessage(GetDlgItem(hwndDlg, IDC_TIMEPMSYMBOL),
CB_GETLBTEXT, (WPARAM)nIndex, (LPARAM)Buffer);
SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, Buffer);
}
else
{
SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, _T(""));
}
SetLocaleInfo(pGlobalData->lcid, LOCALE_S2359, Buffer);
/* Update the time format sample */
UpdateTimeSample(GetDlgItem(hwndDlg, IDC_TIMESAMPLE), pGlobalData->lcid);