From 1b6bea5af7a2f9cfe3b236490851d8df4e27098d Mon Sep 17 00:00:00 2001 From: truckman Date: Wed, 25 May 2016 15:49:29 +0000 Subject: [PATCH] Fix a couple of Coverity Unintended sign extension sign extension defects. When shifting an unsigned byte into the upper 8 bits of an int and the resulting value is greater than 0x7FFFFFF, the result will be sign extended when converting to a 64 bit unsigned long. Fix by casting to (uint64_t) before the shift. Reported by: Coverity CID: 1356044, 1356045 Reviewed by: ken --- sbin/camcontrol/camcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index b5dff1d80605..1b50b864cecd 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -5188,7 +5188,7 @@ get_ata_status(struct cam_device *dev, union ccb *ccb, uint8_t *error, desc->count_7_0; *lba = ((uint64_t)desc->lba_47_40 << 40) | ((uint64_t)desc->lba_39_32 << 32) | - (desc->lba_31_24 << 24) | + ((uint64_t)desc->lba_31_24 << 24) | (desc->lba_23_16 << 16) | (desc->lba_15_8 << 8) | desc->lba_7_0; @@ -5249,7 +5249,7 @@ get_ata_status(struct cam_device *dev, union ccb *ccb, uint8_t *error, (res->lba_low); if (res->flags & CAM_ATAIO_48BIT) { *count |= (res->sector_count_exp << 8); - *lba |= (res->lba_low_exp << 24) | + *lba |= ((uint64_t)res->lba_low_exp << 24) | ((uint64_t)res->lba_mid_exp << 32) | ((uint64_t)res->lba_high_exp << 40); } else {