[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/7] hw/ide/atapi: Be explicit that assigning to s->lcyl truncate
From: |
Peter Maydell |
Subject: |
[PATCH 4/7] hw/ide/atapi: Be explicit that assigning to s->lcyl truncates |
Date: |
Wed, 31 Jul 2024 15:36:14 +0100 |
In ide_atapi_cmd_reply_end() we calculate a 16-bit size, and then
assign its two halves to s->lcyl and s->hcyl like this:
s->lcyl = size;
s->hcyl = size >> 8;
Coverity warns that the first line here can overflow the
8-bit s->lcyl variable. This is true, and in this case we're
deliberately only after the low 8 bits of the value. The
code is clearer to both humans and Coverity if we're explicit
that we only wanted the low 8 bits, though.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/ide/atapi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index fcb6cca1573..e82959dc2d3 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -265,7 +265,7 @@ void ide_atapi_cmd_reply_end(IDEState *s)
byte_count_limit--;
size = byte_count_limit;
}
- s->lcyl = size;
+ s->lcyl = size & 0xff;
s->hcyl = size >> 8;
s->elementary_transfer_size = size;
/* we cannot transmit more than one sector at a time */
--
2.34.1
- [PATCH 0/7] block: Miscellaneous minor Coverity fixes, Peter Maydell, 2024/07/31
- [PATCH 1/7] block/vdi.c: Avoid potential overflow when calculating size of write, Peter Maydell, 2024/07/31
- [PATCH 5/7] hw/block/fdc-isa: Assert that isa_fdc_get_drive_max_chs() found something, Peter Maydell, 2024/07/31
- [PATCH 3/7] hw/block/pflash_cfi01: Don't decrement pfl->counter below 0, Peter Maydell, 2024/07/31
- [PATCH 4/7] hw/ide/atapi: Be explicit that assigning to s->lcyl truncates,
Peter Maydell <=
- [PATCH 7/7] block/ssh.c: Don't double-check that characters are hex digits, Peter Maydell, 2024/07/31
- [PATCH 2/7] block/gluster: Use g_autofree for string in qemu_gluster_parse_json(), Peter Maydell, 2024/07/31
- [PATCH 6/7] hw/ide/pci.c: Remove dead code from bmdma_prepare_buf(), Peter Maydell, 2024/07/31