From: "Liran Alon" <liran.alon@oracle.com>
To: devel@edk2.groups.io, lersek@redhat.com
Cc: sean.brogan@microsoft.com, nikita.leshchenko@oracle.com,
aaron.young@oracle.com, jordan.l.justen@intel.com,
ard.biesheuvel@linaro.org, Liran Alon <liran.alon@oracle.com>
Subject: [PATCH] OvmfPkg/PvScsiDxe: Fix VS2019 build error because of implicit cast
Date: Tue, 31 Mar 2020 14:04:52 +0300 [thread overview]
Message-ID: <20200331110452.51992-1-liran.alon@oracle.com> (raw)
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>
---
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
next reply other threads:[~2020-03-31 11:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-31 11:04 Liran Alon [this message]
2020-03-31 15:53 ` [edk2-devel] [PATCH] OvmfPkg/PvScsiDxe: Fix VS2019 build error because of implicit cast Sean
2020-03-31 21:56 ` Laszlo Ersek
2020-03-31 22:13 ` Liran Alon
2020-03-31 22:17 ` Liran Alon
2020-03-31 22:54 ` Sean
2020-04-01 11:02 ` Laszlo Ersek
2020-04-01 8:36 ` Laszlo Ersek
2020-04-01 8:50 ` Ard Biesheuvel
2020-04-01 11:47 ` Laszlo Ersek
2020-04-01 8:22 ` Laszlo Ersek
2020-04-01 14:46 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200331110452.51992-1-liran.alon@oracle.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox