- Patch by Alex Ionescu: Fix a typo, and code cleanup

svn path=/trunk/; revision=35520
This commit is contained in:
Stefan Ginsberg 2008-08-21 22:41:17 +00:00
parent ea3057f862
commit b9a32878e1

View file

@ -54,51 +54,46 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
IN va_list ap, IN va_list ap,
IN BOOLEAN HandleBreakpoint) IN BOOLEAN HandleBreakpoint)
{ {
NTSTATUS Status; NTSTATUS Status = STATUS_SUCCESS;
ANSI_STRING DebugString; ANSI_STRING DebugString;
CHAR Buffer[512]; CHAR Buffer[512];
PCHAR pBuffer = Buffer; ULONG Length, PrefixLength;
ULONG pBufferSize = sizeof(Buffer);
ULONG Length;
EXCEPTION_RECORD ExceptionRecord; EXCEPTION_RECORD ExceptionRecord;
/* Check if we should print it or not */ /* Check if we should print it or not */
if (ComponentId != -1 && !NtQueryDebugFilterState(ComponentId, Level)) if ((ComponentId != -1) && !(NtQueryDebugFilterState(ComponentId, Level)))
{ {
/* This message is masked */ /* This message is masked */
return STATUS_SUCCESS; return Status;
} }
/* For user mode, don't recursively DbgPrint */ /* For user mode, don't recursively DbgPrint */
if (RtlpSetInDbgPrint(TRUE)) return STATUS_SUCCESS; if (RtlpSetInDbgPrint(TRUE)) return Status;
/* Initialize the length to 8 */ /* Guard against incorrect pointers */
DebugString.Length = 0; _SEH_TRY
/* Handle the prefix */
if (Prefix && *Prefix)
{ {
/* Get the length */ /* Get the length and normalize it */
DebugString.Length = strlen(Prefix); PrefixLength = strlen(Prefix);
if (PrefixLength > sizeof(Buffer)) PrefixLength = sizeof(Buffer);
/* Normalize it */
if(DebugString.Length > sizeof(Buffer))
{
DebugString.Length = sizeof(Buffer);
}
/* Copy it */ /* Copy it */
strncpy(Buffer, Prefix, DebugString.Length); strncpy(Buffer, Prefix, PrefixLength);
/* Set the pointer and update the size */ /* Do the printf */
pBuffer = &Buffer[DebugString.Length]; Length = _vsnprintf(Buffer + PrefixLength,
pBufferSize -= DebugString.Length; sizeof(Buffer) - PrefixLength,
Format,
ap);
} }
_SEH_HANDLE
/* Setup the ANSI String */ {
DebugString.Buffer = Buffer; /* Fail */
DebugString.MaximumLength = sizeof(Buffer); Length = PrefixLength = 0;
Length = _vsnprintf(pBuffer, pBufferSize, Format, ap); Status = _SEH_GetExceptionCode();
}
_SEH_END;
if (!NT_SUCCESS(Status)) return Status;
/* Check if we went past the buffer */ /* Check if we went past the buffer */
if (Length == -1) if (Length == -1)
@ -109,9 +104,15 @@ vDbgPrintExWithPrefixInternal(IN LPCSTR Prefix,
/* Put maximum */ /* Put maximum */
Length = sizeof(Buffer); Length = sizeof(Buffer);
} }
else
/* Update length */ {
DebugString.Length += (USHORT)Length; /* Add the prefix */
Length += PrefixLength;
}
/* Build the string */
DebugString.Length = Length;
DebugString.Buffer = Buffer;
/* First, let the debugger know as well */ /* First, let the debugger know as well */
if (RtlpCheckForActiveDebugger(FALSE)) if (RtlpCheckForActiveDebugger(FALSE))