Fix VS2019 Code Analysis warnings

When compiling for x64, Visual Studio 2019's Code Analysis produces the following warnings:

C:\Projects\gnu-efi\lib\print.c(1380): warning C26451: Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2).
C:\Projects\gnu-efi\lib\smbios.c(47): warning C26451: Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2).
C:\Projects\gnu-efi\lib\str.c(289): warning C26451: Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2).

Fix these by adding an explicit cast to UINTN.
This commit is contained in:
Pete Batard 2021-07-15 12:38:22 +01:00 committed by Nigel Croxon
parent 40160210a7
commit 4ef183353c
3 changed files with 3 additions and 3 deletions

View File

@ -1377,7 +1377,7 @@ ValueToString (
*(p1++) = (CHAR8)r + '0';
}
c = (Comma ? ca[(p1 - str) % 3] : 999) + 1;
c = (UINTN) (Comma ? ca[(p1 - str) % 3] : 999) + 1;
while (p1 != str) {
c -= 1;

View File

@ -44,7 +44,7 @@ LibGetSmbiosSystemGuidAndSerialNumber (
}
Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress;
SmbiosEnd.Raw = (UINT8 *)(SmbiosTable->TableAddress + SmbiosTable->TableLength);
SmbiosEnd.Raw = (UINT8 *)((UINTN)SmbiosTable->TableAddress + SmbiosTable->TableLength);
for (Index = 0; Index < SmbiosTable->TableLength ; Index++) {
if (Smbios.Hdr->Type == 1) {
if (Smbios.Hdr->Length < 0x19) {

View File

@ -286,7 +286,7 @@ xtoi (
}
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
u = (u << 4) | (c - (c >= 'A' ? 'A'-10 : '0'));
u = (u << 4) | ((UINTN)c - (c >= 'A' ? 'A'-10 : '0'));
} else {
break;
}