From a7fc06ddce14375bc6809dd5afee8f2074ce3817 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Sun, 21 Jul 2019 13:09:39 +0300 Subject: [PATCH] OcDebugLogLib: Fix hex logging issues --- Include/Library/OcDebugLogLib.h | 2 +- Library/OcDebugLogLib/DebugPrint.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Include/Library/OcDebugLogLib.h b/Include/Library/OcDebugLogLib.h index 1d7d7ced..0ea3aa3f 100644 --- a/Include/Library/OcDebugLogLib.h +++ b/Include/Library/OcDebugLogLib.h @@ -18,7 +18,7 @@ #include #include -#define OC_HEX_LOWER(x) "0123456789ABCDEF"[(UINT32) (x) >> 4U] +#define OC_HEX_LOWER(x) "0123456789ABCDEF"[((UINT32) (x) & 0x0FU)] #define OC_HEX_UPPER(x) "0123456789ABCDEF"[((UINT32) (x) & 0xF0U) >> 4U] /** diff --git a/Library/OcDebugLogLib/DebugPrint.c b/Library/OcDebugLogLib/DebugPrint.c index f5e3c237..89780274 100644 --- a/Library/OcDebugLogLib/DebugPrint.c +++ b/Library/OcDebugLogLib/DebugPrint.c @@ -49,6 +49,7 @@ DebugPrintHexDump ( UINTN Index; UINTN Index2; UINTN Count; + UINTN SizeLeft; UINTN MaxPerLine; CHAR8 *HexLine; CHAR8 *HexLineCurrent; @@ -61,17 +62,19 @@ DebugPrintHexDump ( return; } + SizeLeft = Size; + for (Index = 0; Index < Count; ++Index) { HexLineCurrent = HexLine; - for (Index2 = 0; Size > 0 && Index2 < MaxPerLine; ++Index) { + for (Index2 = 0; SizeLeft > 0 && Index2 < MaxPerLine; ++Index2) { if (Index2 > 0) { *HexLineCurrent++ = ' '; } *HexLineCurrent++ = OC_HEX_UPPER (*Bytes); *HexLineCurrent++ = OC_HEX_LOWER (*Bytes); - --Size; + --SizeLeft; ++Bytes; } @@ -80,6 +83,7 @@ DebugPrintHexDump ( DEBUG (( ErrorLevel, "%a (%u/%u %u) - %a\n", + Message, (UINT32) Index + 1, (UINT32) Count, (UINT32) Size,