From f67786e381717ee02570d33445ea8c326986b2ac Mon Sep 17 00:00:00 2001 From: Shenglei Zhang Date: Mon, 25 Feb 2019 13:37:56 +0800 Subject: [PATCH] BaseTools/TianoCompress: Improve performance of boundary validation The boundary validation checking in MakeTable() performs on every loop iteration. This could be improved by checking just once before the loop. https://bugzilla.tianocore.org/show_bug.cgi?id=1329 Cc: Bob Feng Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Shenglei Zhang Reviewed-by: Liming Gao --- BaseTools/Source/C/TianoCompress/TianoCompress.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/C/TianoCompress/TianoCompress.c b/BaseTools/Source/C/TianoCompress/TianoCompress.c index 29b11c597f..ae88074360 100644 --- a/BaseTools/Source/C/TianoCompress/TianoCompress.c +++ b/BaseTools/Source/C/TianoCompress/TianoCompress.c @@ -2281,10 +2281,11 @@ Returns: if (Len <= TableBits) { + if (Start[Len] >= NextCode || NextCode > MaxTableLength){ + return (UINT16) BAD_TABLE; + } + for (Index = Start[Len]; Index < NextCode; Index++) { - if (Index >= MaxTableLength) { - return (UINT16) BAD_TABLE; - } Table[Index] = Char; }