diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-02-01 14:53:33 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-02-01 14:53:33 +0000 |
commit | f9cea76b1510fcb475c786fa436b86136c03e309 (patch) | |
tree | ec2aabb351a1e62a82eac4a8f550738e950bdf39 /MdePkg/Library | |
parent | 3e3c809fc1f41e8e25995d68bd121c22eb3bc0b5 (diff) | |
download | edk2-platforms-f9cea76b1510fcb475c786fa436b86136c03e309.tar.xz |
Fix the issues about the loop count for checksum 16,32,64. The input parameters are the buffer size according to Mde Lib spec.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4649 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library')
-rw-r--r-- | MdePkg/Library/BaseLib/CheckSum.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/MdePkg/Library/BaseLib/CheckSum.c b/MdePkg/Library/BaseLib/CheckSum.c index 5f755451c4..8612c7c392 100644 --- a/MdePkg/Library/BaseLib/CheckSum.c +++ b/MdePkg/Library/BaseLib/CheckSum.c @@ -122,14 +122,15 @@ CalculateSum16 ( {
UINT16 Sum;
UINTN Count;
+ UINTN Total;
ASSERT (Buffer != NULL);
ASSERT (((UINTN) Buffer & 0x1) == 0);
ASSERT ((Length & 0x1) == 0);
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
-
- for (Sum = 0, Count = 0; Count < Length; Count++) {
+ Total = Length / sizeof (*Buffer);
+ for (Sum = 0, Count = 0; Count < Total; Count++) {
Sum = (UINT16) (Sum + *(Buffer + Count));
}
@@ -203,14 +204,15 @@ CalculateSum32 ( {
UINT32 Sum;
UINTN Count;
+ UINTN Total;
ASSERT (Buffer != NULL);
ASSERT (((UINTN) Buffer & 0x3) == 0);
ASSERT ((Length & 0x3) == 0);
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
-
- for (Sum = 0, Count = 0; Count < Length; Count++) {
+ Total = Length / sizeof (*Buffer);
+ for (Sum = 0, Count = 0; Count < Total; Count++) {
Sum = Sum + *(Buffer + Count);
}
@@ -284,13 +286,15 @@ CalculateSum64 ( {
UINT64 Sum;
UINTN Count;
+ UINTN Total;
ASSERT (Buffer != NULL);
ASSERT (((UINTN) Buffer & 0x7) == 0);
ASSERT ((Length & 0x7) == 0);
ASSERT (Length <= (MAX_ADDRESS - ((UINTN) Buffer) + 1));
- for (Sum = 0, Count = 0; Count < Length; Count++) {
+ Total = Length / sizeof (*Buffer);
+ for (Sum = 0, Count = 0; Count < Total; Count++) {
Sum = Sum + *(Buffer + Count);
}
|