]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PvScsiDxe: Fix VS2019 build error because of implicit cast
authorLiran Alon <liran.alon@oracle.com>
Tue, 31 Mar 2020 11:04:52 +0000 (14:04 +0300)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 1 Apr 2020 14:12:09 +0000 (14:12 +0000)
Sean reported that VS2019 build produce the following build error:
INFO - PvScsi.c
INFO - Generating code
INFO - d:\a\1\s\OvmfPkg\PvScsiDxe\PvScsi.c(459): error C2220: the
       following warning is treated as an error
INFO - d:\a\1\s\OvmfPkg\PvScsiDxe\PvScsi.c(459): warning C4244: '=':
       conversion from 'const UINT16' to 'UINT8', possible loss of data

This result from an implicit cast from PVSCSI Response->ScsiStatus
(Which is UINT16) to Packet->TargetResponse (Which is UINT8).

Fix this issue by adding an appropriate explicit cast and verify with
assert that this truncation do not result in loss of data.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2651
Reported-by: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Message-Id: <20200331110452.51992-1-liran.alon@oracle.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
[lersek@redhat.com: rewrap VS2019 diags in commit msg for PatchCheck.py]

OvmfPkg/PvScsiDxe/PvScsi.c

index 0a66c98421a91a96c543e3ec913cb46b8201d9b9..1ca50390c0e579addeb09bb3c82994206bbcf2f7 100644 (file)
@@ -455,8 +455,12 @@ HandleResponse (
 \r
   //\r
   // Report target status\r
+  // (Strangely, PVSCSI interface defines Response->ScsiStatus as UINT16.\r
+  // But it should de-facto always have a value that fits UINT8. To avoid\r
+  // unexpected behavior, verify value is in UINT8 bounds before casting)\r
   //\r
-  Packet->TargetStatus = Response->ScsiStatus;\r
+  ASSERT (Response->ScsiStatus <= MAX_UINT8);\r
+  Packet->TargetStatus = (UINT8)Response->ScsiStatus;\r
 \r
   //\r
   // Host adapter status and function return value depend on\r