https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0997e9023c2242974026cc397805318b96425714

commit 0997e9023c2242974026cc397805318b96425714
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Fri Oct 21 19:33:57 2022 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Wed Oct 26 00:41:23 2022 +0200

    [SMSS][NTOS:MM] Get rid of the remaining sprintf_nt hacks. (#4799)
---
 base/system/smss/smss.c   | 19 ++++---------------
 ntoskrnl/mm/ARM3/sysldr.c | 36 ++++++++++++++----------------------
 2 files changed, 18 insertions(+), 37 deletions(-)

diff --git a/base/system/smss/smss.c b/base/system/smss/smss.c
index 6e9fb6081c0..27b8306b87e 100644
--- a/base/system/smss/smss.c
+++ b/base/system/smss/smss.c
@@ -25,18 +25,6 @@ HANDLE SmpInitialCommandProcessId;
 
 /* FUNCTIONS 
******************************************************************/
 
-/* GCC's incompetence strikes again */
-VOID
-sprintf_nt(IN PCHAR Buffer,
-           IN PCHAR Format,
-           IN ...)
-{
-    va_list ap;
-    va_start(ap, Format);
-    sprintf(Buffer, Format, ap);
-    va_end(ap);
-}
-
 NTSTATUS
 NTAPI
 SmpExecuteImage(IN PUNICODE_STRING FileName,
@@ -176,9 +164,10 @@ SmpInvokeAutoChk(IN PUNICODE_STRING FileName,
     if (Flags & SMP_INVALID_PATH)
     {
         /* It wasn't, so create an error message to print on the screen */
-        sprintf_nt(MessageBuffer,
-                   "%wZ program not found - skipping AUTOCHECK\r\n",
-                   FileName);
+        RtlStringCbPrintfA(MessageBuffer,
+                           sizeof(MessageBuffer),
+                           "%wZ program not found - skipping AUTOCHECK\r\n",
+                           FileName);
         RtlInitAnsiString(&MessageString, MessageBuffer);
         if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&Destination,
                                                     &MessageString,
diff --git a/ntoskrnl/mm/ARM3/sysldr.c b/ntoskrnl/mm/ARM3/sysldr.c
index 31181b69fc9..35b538259f3 100644
--- a/ntoskrnl/mm/ARM3/sysldr.c
+++ b/ntoskrnl/mm/ARM3/sysldr.c
@@ -16,19 +16,6 @@
 #define MODULE_INVOLVED_IN_ARM3
 #include <mm/ARM3/miarm.h>
 
-static
-inline
-VOID
-sprintf_nt(IN PCHAR Buffer,
-           IN PCHAR Format,
-           IN ...)
-{
-    va_list ap;
-    va_start(ap, Format);
-    vsprintf(Buffer, Format, ap);
-    va_end(ap);
-}
-
 /* GLOBALS 
********************************************************************/
 
 LIST_ENTRY PsLoadedModuleList;
@@ -2908,7 +2895,7 @@ MmLoadSystemImage(IN PUNICODE_STRING FileName,
     OBJECT_ATTRIBUTES ObjectAttributes;
     IO_STATUS_BLOCK IoStatusBlock;
     PIMAGE_NT_HEADERS NtHeader;
-    UNICODE_STRING BaseName, BaseDirectory, PrefixName, UnicodeTemp;
+    UNICODE_STRING BaseName, BaseDirectory, PrefixName;
     PLDR_DATA_TABLE_ENTRY LdrEntry = NULL;
     ULONG EntrySize, DriverSize;
     PLOAD_IMPORTS LoadedImports = MM_SYSLDR_NO_IMPORTS;
@@ -2920,7 +2907,7 @@ MmLoadSystemImage(IN PUNICODE_STRING FileName,
     BOOLEAN LockOwned = FALSE;
     PLIST_ENTRY NextEntry;
     IMAGE_INFO ImageInfo;
-    STRING AnsiTemp;
+
     PAGED_CODE();
 
     /* Detect session-load */
@@ -3364,6 +3351,9 @@ LoaderScan:
     if (MiCacheImageSymbols(LdrEntry->DllBase))
 #endif
     {
+        UNICODE_STRING UnicodeTemp;
+        STRING AnsiTemp;
+
         /* Check if the system root is present */
         if ((PrefixName.Length > (11 * sizeof(WCHAR))) &&
             !(_wcsnicmp(PrefixName.Buffer, L"\\SystemRoot", 11)))
@@ -3372,18 +3362,20 @@ LoaderScan:
             UnicodeTemp = PrefixName;
             UnicodeTemp.Buffer += 11;
             UnicodeTemp.Length -= (11 * sizeof(WCHAR));
-            sprintf_nt(Buffer,
-                       "%ws%wZ",
-                       &SharedUserData->NtSystemRoot[2],
-                       &UnicodeTemp);
+            RtlStringCbPrintfA(Buffer,
+                               MAXIMUM_FILENAME_LENGTH,
+                               "%ws%wZ",
+                               &SharedUserData->NtSystemRoot[2],
+                               &UnicodeTemp);
         }
         else
         {
             /* Build the name */
-            sprintf_nt(Buffer, "%wZ", &BaseName);
+            RtlStringCbPrintfA(Buffer, MAXIMUM_FILENAME_LENGTH,
+                               "%wZ", &BaseName);
         }
 
-        /* Setup the ansi string */
+        /* Setup the ANSI string */
         RtlInitString(&AnsiTemp, Buffer);
 
         /* Notify the debugger */
@@ -3523,7 +3515,7 @@ MmGetSystemRoutineAddress(IN PUNICODE_STRING 
SystemRoutineName)
     UNICODE_STRING HalName = RTL_CONSTANT_STRING(L"hal.dll");
     ULONG Modules = 0;
 
-    /* Convert routine to ansi name */
+    /* Convert routine to ANSI name */
     Status = RtlUnicodeStringToAnsiString(&AnsiRoutineName,
                                           SystemRoutineName,
                                           TRUE);

Reply via email to