Reactos

[SETUPLIB][USETUP] Use NT RTL String Safe functions instead of Win32-oriented ones (and remove usage of HRESULT too).

Based on:
svn path=/branches/setup_improvements/; revision=75755
svn path=/branches/setup_improvements/; revision=75757

+69 -70
+3 -3
base/setup/lib/bootsup.c
··· 883 883 884 884 #if 0 885 885 WCHAR DestinationDevicePathBuffer[MAX_PATH]; 886 - StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), 887 - L"\\Device\\Harddisk%d\\Partition0", 888 - DiskNumber); 886 + RtlStringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), 887 + L"\\Device\\Harddisk%d\\Partition0", 888 + DiskNumber); 889 889 #endif 890 890 891 891 CombinePaths(SourceMbrPathBuffer, ARRAYSIZE(SourceMbrPathBuffer), 2,
+3 -3
base/setup/lib/mui.c
··· 298 298 { 299 299 if (uIndex > 19) break; 300 300 301 - swprintf(szValueName, L"%u", uIndex + 1); 301 + RtlStringCchPrintfW(szValueName, ARRAYSIZE(szValueName), L"%u", uIndex + 1); 302 302 RtlInitUnicodeString(&ValueName, szValueName); 303 303 304 - swprintf(szLangID, L"0000%s", MuiLayouts[uIndex].LangID); 304 + RtlStringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"0000%s", MuiLayouts[uIndex].LangID); 305 305 306 306 if (_wcsicmp(szLangID, MuiLayouts[uIndex].LayoutID) == 0) 307 307 { ··· 321 321 } 322 322 else 323 323 { 324 - swprintf(szLangID, L"d%03lu%s", uCount, MuiLayouts[uIndex].LangID); 324 + RtlStringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"d%03lu%s", uCount, MuiLayouts[uIndex].LangID); 325 325 Status = NtSetValueKey(KeyHandle, 326 326 &ValueName, 327 327 0,
+2 -5
base/setup/lib/registry.c
··· 34 34 35 35 #include "registry.h" 36 36 37 - // HACK! 38 - #include <strsafe.h> 39 - 40 37 #define NDEBUG 41 38 #include <debug.h> 42 39 ··· 1098 1095 1099 1096 CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 3, 1100 1097 InstallPath->Buffer, L"System32\\config", RegistryHives[i].HiveName); 1101 - StringCchCopyW(DstPath, ARRAYSIZE(DstPath), SrcPath); 1102 - StringCchCatW(DstPath, ARRAYSIZE(DstPath), L".sav"); 1098 + RtlStringCchCopyW(DstPath, ARRAYSIZE(DstPath), SrcPath); 1099 + RtlStringCchCatW(DstPath, ARRAYSIZE(DstPath), L".sav"); 1103 1100 1104 1101 DPRINT1("Copy hive: %S ==> %S\n", SrcPath, DstPath); 1105 1102 Status = SetupCopyFile(SrcPath, DstPath, FALSE);
+14 -12
base/setup/lib/settings.c
··· 422 422 } 423 423 424 424 wcscpy((PWCHAR)*UserData, KeyName); 425 - wcscpy(DisplayText, KeyValue); 425 + RtlStringCbCopyW(DisplayText, DisplayTextSize, KeyValue); 426 426 427 427 *Current = (CompareKey ? !_wcsicmp(KeyName, CompareKey) : FALSE); 428 428 ··· 483 483 } 484 484 485 485 DPRINT("Computer key: %S\n", KeyName); 486 - wcscpy(ComputerKey, KeyName); 486 + RtlStringCchCopyW(ComputerKey, ARRAYSIZE(ComputerKey), KeyName); 487 487 INF_FreeData(KeyName); 488 488 } while (SetupFindNextLine(&Context, &Context)); 489 489 ··· 548 548 BusInstance = 0; 549 549 while (TRUE) 550 550 { 551 - swprintf(Buffer, L"%lu", BusInstance); 551 + RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", BusInstance); 552 552 RtlInitUnicodeString(&KeyName, Buffer); 553 553 InitializeObjectAttributes(&ObjectAttributes, 554 554 &KeyName, ··· 584 584 while (TRUE) 585 585 { 586 586 /* Open the pointer controller instance key */ 587 - swprintf(Buffer, L"%lu", ControllerInstance); 587 + RtlStringCchPrintfW(Buffer, ARRAYSIZE(Buffer), L"%lu", ControllerInstance); 588 588 RtlInitUnicodeString(&KeyName, Buffer); 589 589 InitializeObjectAttributes(&ObjectAttributes, 590 590 &KeyName, ··· 719 719 } 720 720 721 721 DPRINT("Display key: %S\n", KeyName); 722 - wcscpy(DisplayKey, KeyName); 722 + RtlStringCchCopyW(DisplayKey, ARRAYSIZE(DisplayKey), KeyName); 723 723 INF_FreeData(KeyName); 724 724 } while (SetupFindNextLine(&Context, &Context)); 725 725 ··· 764 764 return FALSE; 765 765 } 766 766 767 - wcscpy(SectionName, L"Files."); 768 - wcscat(SectionName, (const wchar_t*)GetListEntryUserData(Entry)); 767 + RtlStringCchPrintfW(SectionName, ARRAYSIZE(SectionName), 768 + L"Files.%s", (PCWSTR)GetListEntryUserData(Entry)); 769 769 *AdditionalSectionName = SectionName; 770 770 771 771 return TRUE; ··· 813 813 ASSERT(wcslen(ServiceName) < 10); 814 814 DPRINT1("Service name: '%S'\n", ServiceName); 815 815 816 - swprintf(RegPath, L"System\\CurrentControlSet\\Services\\%s", ServiceName); 816 + RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath), 817 + L"System\\CurrentControlSet\\Services\\%s", 818 + ServiceName); 817 819 RtlInitUnicodeString(&KeyName, RegPath); 818 820 InitializeObjectAttributes(&ObjectAttributes, 819 821 &KeyName, ··· 850 852 return FALSE; 851 853 } 852 854 853 - swprintf(RegPath, 854 - L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", 855 - ServiceName); 855 + RtlStringCchPrintfW(RegPath, ARRAYSIZE(RegPath), 856 + L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\%s\\Device0", 857 + ServiceName); 856 858 DPRINT1("RegPath: '%S'\n", RegPath); 857 859 RtlInitUnicodeString(&KeyName, RegPath); 858 860 InitializeObjectAttributes(&ObjectAttributes, ··· 1110 1112 } 1111 1113 1112 1114 wcscpy((PWCHAR)*UserData, KeyName); 1113 - wcscpy(DisplayText, KeyValue); 1115 + RtlStringCbCopyW(DisplayText, DisplayTextSize, KeyValue); 1114 1116 1115 1117 *Current = FALSE; 1116 1118
+20 -14
base/setup/lib/setuplib.c
··· 16 16 17 17 #include "setuplib.h" 18 18 19 - // HACK! 20 - #include <strsafe.h> 21 - 22 19 #define NDEBUG 23 20 #include <debug.h> 24 21 ··· 147 144 DPRINT("INF_GetData() failed for key 'InstallationDirectory'\n"); 148 145 goto Quit; 149 146 } 150 - wcscpy(pSetupData->InstallationDirectory, Value); 147 + 148 + RtlStringCchCopyW(pSetupData->InstallationDirectory, 149 + ARRAYSIZE(pSetupData->InstallationDirectory), 150 + Value); 151 + 151 152 INF_FreeData(Value); 152 153 } 153 154 ··· 189 190 if (INF_GetData(&Context, NULL, &Value)) 190 191 { 191 192 LONG Id = wcstol(Value, NULL, 16); 192 - swprintf(pSetupData->LocaleID, L"%08lx", Id); 193 + RtlStringCchPrintfW(pSetupData->LocaleID, 194 + ARRAYSIZE(pSetupData->LocaleID), 195 + L"%08lx", Id); 193 196 INF_FreeData(Value); 194 197 } 195 198 } ··· 233 236 if (IniSection) 234 237 { 235 238 /* Key "skipmissingfiles" */ 236 - // StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 237 - // L"\"%s\"", L"WinNt5.2"); 239 + // RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 240 + // L"\"%s\"", L"WinNt5.2"); 238 241 // IniCacheInsertKey(IniSection, NULL, INSERT_LAST, 239 242 // L"Version", PathBuffer); 240 243 } ··· 242 245 IniSection = IniCacheAppendSection(IniCache, L"Data"); 243 246 if (IniSection) 244 247 { 245 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 246 - L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no"); 248 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 249 + L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no"); 247 250 IniCacheInsertKey(IniSection, NULL, INSERT_LAST, 248 251 L"UnattendedInstall", PathBuffer); 249 252 250 253 // "floppylessbootpath" (yes/no) 251 254 252 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 253 - L"\"%s\"", L"winnt"); 255 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 256 + L"\"%s\"", L"winnt"); 254 257 IniCacheInsertKey(IniSection, NULL, INSERT_LAST, 255 258 L"ProductType", PathBuffer); 256 259 257 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 258 - L"\"%s\\\"", pSetupData->SourceRootPath.Buffer); 260 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 261 + L"\"%s\\\"", pSetupData->SourceRootPath.Buffer); 259 262 IniCacheInsertKey(IniSection, NULL, INSERT_LAST, 260 263 L"SourcePath", PathBuffer); 261 264 ··· 561 564 if (!INF_GetData(&Context, NULL, &Value)) 562 565 return ERROR_CORRUPT_TXTSETUPSIF; 563 566 564 - wcscpy(pSetupData->InstallationDirectory, Value); 567 + RtlStringCchCopyW(pSetupData->InstallationDirectory, 568 + ARRAYSIZE(pSetupData->InstallationDirectory), 569 + Value); 570 + 565 571 INF_FreeData(Value); 566 572 } 567 573
-2
base/setup/lib/utils/arcname_tests.c
··· 20 20 21 21 #include <ntstatus.h> 22 22 23 - #include <strsafe.h> 24 - 25 23 #include "arcname.h" 26 24 27 25 #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
+6 -8
base/setup/lib/utils/genlist.c
··· 21 21 { 22 22 PGENERIC_LIST List; 23 23 24 - List = (PGENERIC_LIST)RtlAllocateHeap(ProcessHeap, 25 - 0, 26 - sizeof(GENERIC_LIST)); 24 + List = RtlAllocateHeap(ProcessHeap, 0, sizeof(GENERIC_LIST)); 27 25 if (List == NULL) 28 26 return NULL; 29 27 ··· 70 68 IN BOOLEAN Current) 71 69 { 72 70 PGENERIC_LIST_ENTRY Entry; 71 + SIZE_T TextSize; 73 72 74 - Entry = (PGENERIC_LIST_ENTRY)RtlAllocateHeap(ProcessHeap, 75 - 0, 76 - sizeof(GENERIC_LIST_ENTRY) + 77 - (wcslen(Text) + 1) * sizeof(WCHAR)); 73 + TextSize = (wcslen(Text) + 1) * sizeof(WCHAR); 74 + Entry = RtlAllocateHeap(ProcessHeap, 0, 75 + sizeof(GENERIC_LIST_ENTRY) + TextSize); 78 76 if (Entry == NULL) 79 77 return FALSE; 80 78 81 - wcscpy(Entry->Text, Text); 79 + RtlStringCbCopyW(Entry->Text, TextSize, Text); 82 80 Entry->List = List; 83 81 Entry->UserData = UserData; 84 82
+6 -6
base/setup/lib/utils/regutil.c
··· 13 13 14 14 #include "regutil.h" 15 15 16 - // HACK! 17 - #include <strsafe.h> 18 - 19 16 #define NDEBUG 20 17 #include <debug.h> 21 18 ··· 180 177 181 178 // i = 1; 182 179 /* Try first by just appending the '.old' extension */ 183 - StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s.%s", PathBuffer, Extension); 180 + RtlStringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), 181 + L"%s.%s", PathBuffer, Extension); 184 182 #if 0 185 183 while (DoesFileExist(NULL, PathBuffer2)) 186 184 { ··· 188 186 if (i <= 0xFFFF) 189 187 { 190 188 /* Append '_N.old' extension */ 191 - StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s_%lu.%s", PathBuffer, i, Extension); 189 + RtlStringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), 190 + L"%s_%lu.%s", PathBuffer, i, Extension); 192 191 ++i; 193 192 } 194 193 else ··· 197 196 * Too many old files exist, we will rename the file 198 197 * using the name of the oldest one. 199 198 */ 200 - StringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), L"%s.%s", PathBuffer, Extension); 199 + RtlStringCchPrintfW(PathBuffer2, ARRAYSIZE(PathBuffer2), 200 + L"%s.%s", PathBuffer, Extension); 201 201 break; 202 202 } 203 203 }
+14 -17
base/setup/usetup/usetup.c
··· 36 36 #define NDEBUG 37 37 #include <debug.h> 38 38 39 - // HACK! 40 - #include <strsafe.h> 41 - 42 39 43 40 /* GLOBALS & LOCALS *********************************************************/ 44 41 ··· 1679 1676 return SELECT_PARTITION_PAGE; 1680 1677 } 1681 1678 1682 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 1679 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 1683 1680 L"\\Device\\Harddisk%lu\\Partition%lu\\", 1684 1681 PartitionList->CurrentDisk->DiskNumber, 1685 1682 PartitionList->CurrentPartition->PartitionNumber); ··· 3007 3004 } 3008 3005 3009 3006 /* Set PartitionRootPath */ 3010 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3007 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3011 3008 L"\\Device\\Harddisk%lu\\Partition%lu", 3012 3009 DiskEntry->DiskNumber, 3013 3010 PartEntry->PartitionNumber); ··· 3080 3077 } 3081 3078 3082 3079 /* Set PartitionRootPath */ 3083 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3080 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3084 3081 L"\\Device\\Harddisk%lu\\Partition%lu", 3085 3082 DiskEntry->DiskNumber, 3086 3083 PartEntry->PartitionNumber); ··· 3171 3168 3172 3169 /* Create 'USetupData.DestinationRootPath' string */ 3173 3170 RtlFreeUnicodeString(&USetupData.DestinationRootPath); 3174 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3171 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3175 3172 L"\\Device\\Harddisk%lu\\Partition%lu\\", 3176 3173 DiskEntry->DiskNumber, 3177 3174 PartEntry->PartitionNumber); ··· 3188 3185 /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ 3189 3186 /* Create 'USetupData.DestinationArcPath' */ 3190 3187 RtlFreeUnicodeString(&USetupData.DestinationArcPath); 3191 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3188 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 3192 3189 L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", 3193 3190 DiskEntry->BiosDiskNumber, 3194 3191 PartEntry->PartitionNumber); ··· 3598 3595 /* Installation path */ 3599 3596 DPRINT("InstallationPath: '%S'\n", DirKeyValue); 3600 3597 3601 - StringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 3602 - USetupData.SourceRootDir.Buffer); 3598 + RtlStringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 3599 + USetupData.SourceRootDir.Buffer); 3603 3600 3604 3601 DPRINT("InstallationPath(2): '%S'\n", CompleteOrigDirName); 3605 3602 } ··· 3608 3605 /* Absolute path */ 3609 3606 DPRINT("AbsolutePath: '%S'\n", DirKeyValue); 3610 3607 3611 - StringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 3612 - DirKeyValue); 3608 + RtlStringCchCopyW(CompleteOrigDirName, ARRAYSIZE(CompleteOrigDirName), 3609 + DirKeyValue); 3613 3610 3614 3611 DPRINT("AbsolutePath(2): '%S'\n", CompleteOrigDirName); 3615 3612 } ··· 3684 3681 */ 3685 3682 3686 3683 /* Get destination path */ 3687 - StringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), USetupData.DestinationPath.Buffer); 3684 + RtlStringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), USetupData.DestinationPath.Buffer); 3688 3685 3689 3686 DPRINT("FullPath(1): '%S'\n", PathBuffer); 3690 3687 ··· 3726 3723 /* Installation path */ 3727 3724 DPRINT("InstallationPath: '%S'\n", DirKeyValue); 3728 3725 3729 - StringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), 3730 - USetupData.DestinationPath.Buffer); 3726 + RtlStringCchCopyW(PathBuffer, ARRAYSIZE(PathBuffer), 3727 + USetupData.DestinationPath.Buffer); 3731 3728 3732 3729 DPRINT("InstallationPath(2): '%S'\n", PathBuffer); 3733 3730 } ··· 4321 4318 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); 4322 4319 4323 4320 RtlFreeUnicodeString(&USetupData.SystemRootPath); 4324 - StringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 4321 + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), 4325 4322 L"\\Device\\Harddisk%lu\\Partition%lu\\", 4326 4323 PartitionList->SystemPartition->DiskEntry->DiskNumber, 4327 4324 PartitionList->SystemPartition->PartitionNumber); ··· 4620 4617 } 4621 4618 4622 4619 /* Step 2: Write the MBR */ 4623 - StringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), 4620 + RtlStringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer), 4624 4621 L"\\Device\\Harddisk%d\\Partition0", 4625 4622 PartitionList->SystemPartition->DiskEntry->DiskNumber); 4626 4623 Status = InstallMbrBootCodeToDisk(&USetupData.SystemRootPath,
+1
base/setup/usetup/usetup.h
··· 52 52 53 53 #include <ntstrsafe.h> 54 54 55 + 55 56 /* Setup library headers */ 56 57 #include <reactos/rosioctl.h> 57 58 #include <../lib/setuplib.h>