v2: Fix the wrong condition in for cycle. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1456
For the NET_LIST_FOR_EACH & NET_LIST_FOR_EACH_SAFE, "Entry" should be checked whether it's NULL or not instead of using the pointer directly. Cc: Wu Hao A <hao.a...@intel.com> Cc: Gao Liming <liming....@intel.com> Cc: Ye Ting <ting...@intel.com> Cc: Fu Siyuan <siyuan...@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin <jiaxin...@intel.com> --- MdeModulePkg/Include/Library/NetLib.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h index 0977973921..c9a86733ec 100644 --- a/MdeModulePkg/Include/Library/NetLib.h +++ b/MdeModulePkg/Include/Library/NetLib.h @@ -616,21 +616,21 @@ NetRandomInitSeed ( // // Iterate through the double linked list. It is NOT delete safe // #define NET_LIST_FOR_EACH(Entry, ListHead) \ - for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink) + for(Entry = (ListHead)->ForwardLink; Entry != (ListHead) && Entry != NULL; Entry = Entry->ForwardLink) // // Iterate through the double linked list. This is delete-safe. // Don't touch NextEntry. Also, don't use this macro if list // entries other than the Entry may be deleted when processing // the current Entry. // #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \ - for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \ - Entry != (ListHead); \ + for(Entry = (ListHead)->ForwardLink, (Entry != NULL) ? (NextEntry = Entry->ForwardLink) : (Entry = NULL); \ + Entry != (ListHead) && Entry != NULL; \ Entry = NextEntry, NextEntry = Entry->ForwardLink \ ) // // Make sure the list isn't empty before getting the first/last record. -- 2.17.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel