From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 237A081C5C for ; Wed, 14 Dec 2016 03:27:07 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 14 Dec 2016 03:27:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="1071935641" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by orsmga001.jf.intel.com with ESMTP; 14 Dec 2016 03:27:05 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Fu Siyuan , Ye Ting , Wu Jiaxin Date: Wed, 14 Dec 2016 19:26:49 +0800 Message-Id: <1481714811-12568-5-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1481714811-12568-1-git-send-email-hao.a.wu@intel.com> References: <1481714811-12568-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH 4/6] MdeModulePkg/DxeNetLib: Rewrite NetblockChecksum function logic X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Dec 2016 11:27:07 -0000 This commit rewrites the logic for NetblockChecksum. It processes the checksum of the left-over byte first to prevent possible mis-reports by static code checkers. Cc: Fu Siyuan Cc: Ye Ting Cc: Wu Jiaxin Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c index bbbdbc0..95cb717 100644 --- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c +++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c @@ -1,7 +1,7 @@ /** @file Network library functions providing net buffer operation support. -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1661,6 +1661,13 @@ NetblockChecksum ( Sum = 0; + // + // Add left-over byte, if any + // + if (Len % 2 != 0) { + Sum += *(Bulk + Len - 1); + } + while (Len > 1) { Sum += *(UINT16 *) Bulk; Bulk += 2; @@ -1668,13 +1675,6 @@ NetblockChecksum ( } // - // Add left-over byte, if any - // - if (Len > 0) { - Sum += *(UINT8 *) Bulk; - } - - // // Fold 32-bit sum to 16 bits // while ((Sum >> 16) != 0) { -- 1.9.5.msysgit.0