[edk2-devel] [PATCH] OvmfPkg/PvScsiDxe: Fix VS2019 build error because of implicit cast
Liran Alon
liran.alon at oracle.com
Tue Mar 31 11:04:52 UTC 2020
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 at microsoft.com>
Signed-off-by: Liran Alon <liran.alon at oracle.com>
---
OvmfPkg/PvScsiDxe/PvScsi.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c
index 0a66c98421a9..1ca50390c0e5 100644
--- a/OvmfPkg/PvScsiDxe/PvScsi.c
+++ b/OvmfPkg/PvScsiDxe/PvScsi.c
@@ -455,8 +455,12 @@ HandleResponse (
//
// Report target status
+ // (Strangely, PVSCSI interface defines Response->ScsiStatus as UINT16.
+ // But it should de-facto always have a value that fits UINT8. To avoid
+ // unexpected behavior, verify value is in UINT8 bounds before casting)
//
- Packet->TargetStatus = Response->ScsiStatus;
+ ASSERT (Response->ScsiStatus <= MAX_UINT8);
+ Packet->TargetStatus = (UINT8)Response->ScsiStatus;
//
// Host adapter status and function return value depend on
--
2.20.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#56747): https://edk2.groups.io/g/devel/message/56747
Mute This Topic: https://groups.io/mt/72673992/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list