From 364f4efa444150df3f074f563374dce1e153adc6 Mon Sep 17 00:00:00 2001 From: Zhang Lubo Date: Fri, 8 Apr 2016 09:48:14 +0800 Subject: MdeModulePkg: Add new macros and refine codes Add 2 macros inNetLib.h #define IP4_MASK_MAX 32 #define IP6_PREFIX_MAX 128 we will use these two macros to check the max mask/prefix length, instead of #define IP4_MASK_NUM 33 #define IP6_PREFIX_NUM 129 which means a valid number. This will make the code readability and maintainability. Cc: Subramanian Sriram Cc: Fu Siyuan Cc: Ye Ting Cc: Wu Jiaxin Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo Reviewed-by: Sriram Subramanian --- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'MdeModulePkg/Library/DxeNetLib/DxeNetLib.c') diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c index ebc3e125a2..4acd0fad2c 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -565,7 +565,7 @@ NetGetMaskLength ( { INTN Index; - for (Index = 0; Index < IP4_MASK_NUM; Index++) { + for (Index = 0; Index <= IP4_MASK_MAX; Index++) { if (NetMask == gIp4AllMasks[Index]) { break; } @@ -794,7 +794,7 @@ NetIp6IsNetEqual ( UINT8 Bit; UINT8 Mask; - ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_NUM)); + ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength <= IP6_PREFIX_MAX)); if (PrefixLength == 0) { return TRUE; @@ -3115,7 +3115,7 @@ NetLibStrToIp6andPrefix ( while (*PrefixStr != '\0') { if (NET_IS_DIGIT (*PrefixStr)) { Length = (UINT8) (Length * 10 + (*PrefixStr - '0')); - if (Length >= IP6_PREFIX_NUM) { + if (Length > IP6_PREFIX_MAX) { goto Exit; } } else { -- cgit v1.2.3