[SETUPLIB][USETUP] Use NT RTL String Safe functions instead of Win32-oriented ones...
[reactos.git] / base / setup / lib / settings.c
index bf9a804..060c671 100644 (file)
@@ -323,7 +323,7 @@ typedef UCHAR
 (NTAPI *PPROCESS_ENTRY_ROUTINE)(
     IN PWCHAR KeyName,
     IN PWCHAR KeyValue,
-    IN PCHAR DisplayText,
+    OUT PWCHAR DisplayText,
     IN SIZE_T DisplayTextSize,
     OUT PVOID* UserData,
     OUT PBOOLEAN Current,
@@ -344,7 +344,7 @@ AddEntriesFromInfSection(
     PVOID UserData;
     BOOLEAN Current;
     UCHAR RetVal;
-    CHAR DisplayText[128];
+    WCHAR DisplayText[128];
 
     if (!SetupFindFirstLineW(InfFile, SectionName, NULL, pContext))
         return -1;
@@ -404,7 +404,7 @@ NTAPI
 DefaultProcessEntry(
     IN PWCHAR KeyName,
     IN PWCHAR KeyValue,
-    IN PCHAR DisplayText,
+    OUT PWCHAR DisplayText,
     IN SIZE_T DisplayTextSize,
     OUT PVOID* UserData,
     OUT PBOOLEAN Current,
@@ -422,7 +422,7 @@ DefaultProcessEntry(
     }
 
     wcscpy((PWCHAR)*UserData, KeyName);
-    sprintf(DisplayText, "%S", KeyValue);
+    RtlStringCbCopyW(DisplayText, DisplayTextSize, KeyValue);
 
     *Current = (CompareKey ? !_wcsicmp(KeyName, CompareKey) : FALSE);
 
@@ -483,7 +483,7 @@ CreateComputerTypeList(
         }
 
         DPRINT("Computer key: %S\n", KeyName);
-        wcscpy(ComputerKey, KeyName);
+        RtlStringCchCopyW(ComputerKey, ARRAYSIZE(ComputerKey), KeyName);
         INF_FreeData(KeyName);
     } while (SetupFindNextLine(&Context, &Context));
 
@@ -548,7 +548,7 @@ GetDisplayIdentifier(
     BusInstance = 0;
     while (TRUE)
     {
-        swprintf(Buffer, L"%lu", BusInstance);
+        RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", BusInstance);
         RtlInitUnicodeString(&KeyName, Buffer);
         InitializeObjectAttributes(&ObjectAttributes,
                                    &KeyName,
@@ -584,7 +584,7 @@ GetDisplayIdentifier(
             while (TRUE)
             {
                 /* Open the pointer controller instance key */
-                swprintf(Buffer, L"%lu", ControllerInstance);
+                RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", ControllerInstance);
                 RtlInitUnicodeString(&KeyName, Buffer);
                 InitializeObjectAttributes(&ObjectAttributes,
                                            &KeyName,
@@ -719,7 +719,7 @@ CreateDisplayDriverList(
         }
 
         DPRINT("Display key: %S\n", KeyName);
-        wcscpy(DisplayKey, KeyName);
+        RtlStringCchCopyW(DisplayKey, ARRAYSIZE(DisplayKey), KeyName);
         INF_FreeData(KeyName);
     } while (SetupFindNextLine(&Context, &Context));
 
@@ -739,7 +739,7 @@ CreateDisplayDriverList(
     }
 
 #if 0
-    AppendGenericListEntry(List, "Other display driver", NULL, TRUE);
+    AppendGenericListEntry(List, L"Other display driver", NULL, TRUE);
 #endif
 
     return List;
@@ -764,8 +764,8 @@ ProcessComputerFiles(
         return FALSE;
     }
 
-    wcscpy(SectionName, L"Files.");
-    wcscat(SectionName, (const wchar_t*)GetListEntryUserData(Entry));
+    RtlStringCchPrintfW(SectionName, ARRAYSIZE(SectionName),
+                        L"Files.%s", (PCWSTR)GetListEntryUserData(Entry));
     *AdditionalSectionName = SectionName;
 
     return TRUE;
@@ -813,7 +813,9 @@ ProcessDisplayRegistry(
     ASSERT(wcslen(ServiceName) < 10);
     DPRINT1("Service name: '%S'\n", ServiceName);
 
-    swprintf(RegPath, L"System\\CurrentControlSet\\Services\\%s", ServiceName);
+    RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath),
+                        L"System\\CurrentControlSet\\Services\\%s",
+                        ServiceName);
     RtlInitUnicodeString(&KeyName, RegPath);
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
@@ -850,9 +852,9 @@ ProcessDisplayRegistry(
         return FALSE;
     }
 
-    swprintf(RegPath,
-             L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0",
-             ServiceName);
+    RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath),
+                        L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0",
+                        ServiceName);
     DPRINT1("RegPath: '%S'\n", RegPath);
     RtlInitUnicodeString(&KeyName, RegPath);
     InitializeObjectAttributes(&ObjectAttributes,
@@ -1086,7 +1088,7 @@ NTAPI
 ProcessLangEntry(
     IN PWCHAR KeyName,
     IN PWCHAR KeyValue,
-    IN PCHAR DisplayText,
+    OUT PWCHAR DisplayText,
     IN SIZE_T DisplayTextSize,
     OUT PVOID* UserData,
     OUT PBOOLEAN Current,
@@ -1110,7 +1112,7 @@ ProcessLangEntry(
     }
 
     wcscpy((PWCHAR)*UserData, KeyName);
-    sprintf(DisplayText, "%S", KeyValue);
+    RtlStringCbCopyW(DisplayText, DisplayTextSize, KeyValue);
 
     *Current = FALSE;