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.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
/** @file\r
Network library functions providing net buffer operation support.\r
\r
/** @file\r
Network library functions providing net buffer operation support.\r
\r
-Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
+ //\r
+ // Add left-over byte, if any\r
+ //\r
+ if (Len % 2 != 0) {\r
+ Sum += *(Bulk + Len - 1);\r
+ }\r
+\r
while (Len > 1) {\r
Sum += *(UINT16 *) Bulk;\r
Bulk += 2;\r
Len -= 2;\r
}\r
\r
while (Len > 1) {\r
Sum += *(UINT16 *) Bulk;\r
Bulk += 2;\r
Len -= 2;\r
}\r
\r
- //\r
- // Add left-over byte, if any\r
- //\r
- if (Len > 0) {\r
- Sum += *(UINT8 *) Bulk;\r
- }\r
-\r
//\r
// Fold 32-bit sum to 16 bits\r
//\r
//\r
// Fold 32-bit sum to 16 bits\r
//\r