Author: hpoussin
Date: Wed Jan 9 12:40:47 2008
New Revision: 31682
URL:
http://svn.reactos.org/svn/reactos?rev=31682&view=rev
Log:
Add 'const' when needed
Remove a string copy (an a possible buffer overflow)
Modified:
trunk/reactos/base/setup/usetup/interface/usetup.c
trunk/reactos/base/setup/usetup/mui.c
trunk/reactos/base/setup/usetup/mui.h
Modified: trunk/reactos/base/setup/usetup/interface/usetup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/interfac…
==============================================================================
--- trunk/reactos/base/setup/usetup/interface/usetup.c (original)
+++ trunk/reactos/base/setup/usetup/interface/usetup.c Wed Jan 9 12:40:47 2008
@@ -199,8 +199,8 @@
}
VOID
-PopupError(PCHAR Text,
- PCHAR Status,
+PopupError(PCCH Text,
+ PCCH Status,
PINPUT_RECORD Ir,
ULONG WaitEvent)
{
@@ -212,7 +212,7 @@
ULONG MaxLength;
ULONG Lines;
PCHAR p;
- PCHAR pnext;
+ PCCH pnext;
BOOLEAN LastLine;
SHORT Width;
SHORT Height;
@@ -560,14 +560,14 @@
DPRINT("Running unattended setup\n");
}
-void
-UpdateKBLayout()
+VOID
+UpdateKBLayout(VOID)
{
PLIST_ENTRY Entry;
PGENERIC_LIST_ENTRY ListEntry;
- WCHAR szNewLayout[20];
-
- MUIDefaultKeyboardLayout(szNewLayout);
+ LPCWSTR pszNewLayout;
+
+ pszNewLayout = MUIDefaultKeyboardLayout();
if (LayoutList == NULL)
{
@@ -575,17 +575,22 @@
}
Entry = LayoutList->ListHead.Flink;
- while (Entry != &LayoutList->ListHead)
- {
- ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry);
-
- if (!wcscmp(szNewLayout, ListEntry->UserData))
- {
- LayoutList->CurrentEntry = ListEntry;
- break;
- }
-
- Entry = Entry->Flink;
+
+ /* Search for default layout (if provided) */
+ if (pszNewLayout != NULL)
+ {
+ while (Entry != &LayoutList->ListHead)
+ {
+ ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry);
+
+ if (!wcscmp(pszNewLayout, ListEntry->UserData))
+ {
+ LayoutList->CurrentEntry = ListEntry;
+ break;
+ }
+
+ Entry = Entry->Flink;
+ }
}
}
Modified: trunk/reactos/base/setup/usetup/mui.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/mui.c?re…
==============================================================================
--- trunk/reactos/base/setup/usetup/mui.c (original)
+++ trunk/reactos/base/setup/usetup/mui.c Wed Jan 9 12:40:47 2008
@@ -42,7 +42,7 @@
#include "lang/sv-SE.h"
#include "lang/uk-UA.h"
-static MUI_LANGUAGE LanguageList[] =
+static const MUI_LANGUAGE LanguageList[] =
{
{
L"00000409", /* The Language ID */
@@ -155,18 +155,18 @@
extern
VOID
-PopupError(PCHAR Text,
- PCHAR Status,
- PINPUT_RECORD Ir,
- ULONG WaitEvent);
+PopupError(IN PCCH Text,
+ IN PCCH Status,
+ IN PINPUT_RECORD Ir,
+ IN ULONG WaitEvent);
static
-MUI_ENTRY *
-FindMUIEntriesOfPage (ULONG PageNumber)
+const MUI_ENTRY *
+FindMUIEntriesOfPage(IN ULONG PageNumber)
{
ULONG muiIndex = 0;
ULONG lngIndex = 0;
- MUI_PAGE * Pages = NULL;
+ const MUI_PAGE * Pages = NULL;
do
{
@@ -195,8 +195,8 @@
}
static
-MUI_ERROR *
-FindMUIErrorEntries ()
+const MUI_ERROR *
+FindMUIErrorEntries(VOID)
{
ULONG lngIndex = 0;
@@ -216,8 +216,8 @@
return NULL;
}
-VOID
-MUIDefaultKeyboardLayout(WCHAR * KeyboardLayout)
+LPCWSTR
+MUIDefaultKeyboardLayout(VOID)
{
ULONG lngIndex = 0;
do
@@ -225,26 +225,25 @@
/* First we search the language list till we find current selected language
messages */
if (_wcsicmp(LanguageList[lngIndex].LanguageID , SelectedLanguageId) == 0)
{
- /* Get all available error messages for this language */
- wcscpy(KeyboardLayout, LanguageList[lngIndex].LanguageKeyboardLayoutID);
- return;
+ /* Return default keyboard layout */
+ return LanguageList[lngIndex].LanguageKeyboardLayoutID;
}
lngIndex++;
}
while (LanguageList[lngIndex].MuiPages != NULL);
- KeyboardLayout[0] = L'\0';
+ return NULL;
}
VOID
-MUIDisplayPage(ULONG page)
-{
- MUI_ENTRY * entry;
+MUIDisplayPage(IN ULONG page)
+{
+ const MUI_ENTRY * entry;
int index;
int flags;
- entry = FindMUIEntriesOfPage (page);
+ entry = FindMUIEntriesOfPage(page);
if (!entry)
{
PopupError("Error: Failed to find translated page",
@@ -281,13 +280,13 @@
}
VOID
-MUIDisplayError(ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent)
-{
- MUI_ERROR * entry;
+MUIDisplayError(IN ULONG ErrorNum, OUT PINPUT_RECORD Ir, IN ULONG WaitEvent)
+{
+ const MUI_ERROR * entry;
if (ErrorNum >= ERROR_LAST_ERROR_CODE)
{
- PopupError("Pnvalid error number provided",
+ PopupError("Invalid error number provided",
"Press ENTER to continue",
Ir,
POPUP_WAIT_ENTER);
@@ -295,7 +294,7 @@
return;
}
- entry = FindMUIErrorEntries ();
+ entry = FindMUIErrorEntries();
if (!entry)
{
PopupError("Error: Failed to find translated error message",
@@ -312,7 +311,7 @@
}
static BOOLEAN
-AddCodepageToRegistry(PWCHAR ACPage, PWCHAR OEMCPage, PWCHAR MACCPage)
+AddCodepageToRegistry(IN LPCWSTR ACPage, IN LPCWSTR OEMCPage, IN LPCWSTR MACCPage)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
@@ -322,15 +321,15 @@
// Open the nls codepage key
RtlInitUnicodeString(&KeyName,
-
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
+
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage");
InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
+ &KeyName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
Status = NtOpenKey(&KeyHandle,
- KEY_ALL_ACCESS,
- &ObjectAttributes);
+ KEY_WRITE,
+ &ObjectAttributes);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtOpenKey() failed (Status %lx)\n", Status);
@@ -340,11 +339,11 @@
// Set ANSI codepage
RtlInitUnicodeString(&ValueName, L"ACP");
Status = NtSetValueKey(KeyHandle,
- &ValueName,
- 0,
- REG_SZ,
- (PVOID)ACPage,
- 4 * sizeof(PWCHAR));
+ &ValueName,
+ 0,
+ REG_SZ,
+ (PVOID)ACPage,
+ wcslen(ACPage) * sizeof(PWCHAR));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@@ -355,11 +354,11 @@
// Set OEM codepage
RtlInitUnicodeString(&ValueName, L"OEMCP");
Status = NtSetValueKey(KeyHandle,
- &ValueName,
- 0,
- REG_SZ,
- (PVOID)OEMCPage,
- 3 * sizeof(PWCHAR));
+ &ValueName,
+ 0,
+ REG_SZ,
+ (PVOID)OEMCPage,
+ wcslen(OEMCPage) * sizeof(PWCHAR));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@@ -370,11 +369,11 @@
// Set MAC codepage
RtlInitUnicodeString(&ValueName, L"MACCP");
Status = NtSetValueKey(KeyHandle,
- &ValueName,
- 0,
- REG_SZ,
- (PVOID)MACCPage,
- 5 * sizeof(PWCHAR));
+ &ValueName,
+ 0,
+ REG_SZ,
+ (PVOID)MACCPage,
+ wcslen(MACCPage) * sizeof(PWCHAR));
if (!NT_SUCCESS(Status))
{
DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@@ -403,7 +402,8 @@
lngIndex++;
}
while (LanguageList[lngIndex].MuiPages != NULL);
- return FALSE;
+
+ return FALSE;
}
/* EOF */
Modified: trunk/reactos/base/setup/usetup/mui.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/usetup/mui.h?re…
==============================================================================
--- trunk/reactos/base/setup/usetup/mui.h (original)
+++ trunk/reactos/base/setup/usetup/mui.h Wed Jan 9 12:40:47 2008
@@ -5,19 +5,19 @@
{
BYTE X;
BYTE Y;
- CHAR * Buffer;
+ LPCSTR Buffer;
BYTE Flags;
}MUI_ENTRY, *PMUI_ENTRY;
typedef struct
{
- CHAR * ErrorText;
- CHAR * ErrorStatus;
+ LPCSTR ErrorText;
+ LPCSTR ErrorStatus;
}MUI_ERROR;
typedef struct
{
- long Number;
+ LONG Number;
MUI_ENTRY * MuiEntry;
}MUI_PAGE;
@@ -29,8 +29,8 @@
PWCHAR OEMCPage;
PWCHAR MACCPage;
PWCHAR LanguageDescriptor;
- MUI_PAGE * MuiPages;
- MUI_ERROR * MuiErrors;
+ const MUI_PAGE * MuiPages;
+ const MUI_ERROR * MuiErrors;
}MUI_LANGUAGE;
@@ -50,8 +50,8 @@
VOID
MUIDisplayError (ULONG ErrorNum, PINPUT_RECORD Ir, ULONG WaitEvent);
-VOID
-MUIDefaultKeyboardLayout(WCHAR * KeyboardLayout);
+LPCWSTR
+MUIDefaultKeyboardLayout(VOID);
BOOLEAN
AddCodePage(VOID);