Author: sginsberg
Date: Thu Aug 21 17:41:17 2008
New Revision: 35520
URL:
http://svn.reactos.org/svn/reactos?rev=35520&view=rev
Log:
- Patch by Alex Ionescu: Fix a typo, and code cleanup
Modified:
trunk/reactos/lib/rtl/debug.c
Modified: trunk/reactos/lib/rtl/debug.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/debug.c?rev=35520&…
==============================================================================
--- trunk/reactos/lib/rtl/debug.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/debug.c [iso-8859-1] Thu Aug 21 17:41:17 2008
@@ -54,51 +54,46 @@
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;
-
- /* Initialize the length to 8 */
- DebugString.Length = 0;
-
- /* Handle the prefix */
- if (Prefix && *Prefix)
- {
- /* Get the length */
- DebugString.Length = strlen(Prefix);
-
- /* Normalize it */
- if(DebugString.Length > sizeof(Buffer))
- {
- DebugString.Length = sizeof(Buffer);
- }
+ if (RtlpSetInDbgPrint(TRUE)) return Status;
+
+ /* Guard against incorrect pointers */
+ _SEH_TRY
+ {
+ /* 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;
- }
-
- /* Setup the ANSI String */
- DebugString.Buffer = Buffer;
- DebugString.MaximumLength = sizeof(Buffer);
- Length = _vsnprintf(pBuffer, pBufferSize, Format, ap);
+ strncpy(Buffer, Prefix, PrefixLength);
+
+ /* Do the printf */
+ Length = _vsnprintf(Buffer + PrefixLength,
+ sizeof(Buffer) - PrefixLength,
+ 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 @@
/* 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))