From b9a32878e1a2e6e332ae59a97fed00a4be5f9f03 Mon Sep 17 00:00:00 2001 From: Stefan Ginsberg Date: Thu, 21 Aug 2008 22:41:17 +0000 Subject: [PATCH] - Patch by Alex Ionescu: Fix a typo, and code cleanup svn path=/trunk/; revision=35520 --- reactos/lib/rtl/debug.c | 67 +++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/reactos/lib/rtl/debug.c b/reactos/lib/rtl/debug.c index 5993cd02e8e..adf85b47709 100644 --- a/reactos/lib/rtl/debug.c +++ b/reactos/lib/rtl/debug.c @@ -54,51 +54,46 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix, IN va_list ap, IN BOOLEAN HandleBreakpoint) { - NTSTATUS Status; + NTSTATUS Status = STATUS_SUCCESS; ANSI_STRING DebugString; CHAR Buffer[512]; - PCHAR pBuffer = Buffer; - ULONG pBufferSize = sizeof(Buffer); - ULONG Length; + ULONG Length, PrefixLength; EXCEPTION_RECORD ExceptionRecord; /* Check if we should print it or not */ - if (ComponentId != -1 && !NtQueryDebugFilterState(ComponentId, Level)) + if ((ComponentId != -1) && !(NtQueryDebugFilterState(ComponentId, Level))) { /* This message is masked */ - return STATUS_SUCCESS; + return Status; } /* For user mode, don't recursively DbgPrint */ - if (RtlpSetInDbgPrint(TRUE)) return STATUS_SUCCESS; + if (RtlpSetInDbgPrint(TRUE)) return Status; - /* Initialize the length to 8 */ - DebugString.Length = 0; - - /* Handle the prefix */ - if (Prefix && *Prefix) + /* Guard against incorrect pointers */ + _SEH_TRY { - /* Get the length */ - DebugString.Length = strlen(Prefix); - - /* Normalize it */ - if(DebugString.Length > sizeof(Buffer)) - { - DebugString.Length = sizeof(Buffer); - } + /* Get the length and normalize it */ + PrefixLength = strlen(Prefix); + if (PrefixLength > sizeof(Buffer)) PrefixLength = sizeof(Buffer); /* Copy it */ - strncpy(Buffer, Prefix, DebugString.Length); - - /* Set the pointer and update the size */ - pBuffer = &Buffer[DebugString.Length]; - pBufferSize -= DebugString.Length; + strncpy(Buffer, Prefix, PrefixLength); + + /* Do the printf */ + Length = _vsnprintf(Buffer + PrefixLength, + sizeof(Buffer) - PrefixLength, + Format, + ap); } - - /* Setup the ANSI String */ - DebugString.Buffer = Buffer; - DebugString.MaximumLength = sizeof(Buffer); - Length = _vsnprintf(pBuffer, pBufferSize, Format, ap); + _SEH_HANDLE + { + /* Fail */ + Length = PrefixLength = 0; + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + if (!NT_SUCCESS(Status)) return Status; /* Check if we went past the buffer */ if (Length == -1) @@ -109,9 +104,15 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix, /* Put maximum */ Length = sizeof(Buffer); } - - /* Update length */ - DebugString.Length += (USHORT)Length; + else + { + /* Add the prefix */ + Length += PrefixLength; + } + + /* Build the string */ + DebugString.Length = Length; + DebugString.Buffer = Buffer; /* First, let the debugger know as well */ if (RtlpCheckForActiveDebugger(FALSE))