PVS V1028: cast result of operation instead of operands

If an overflow occurs before the cast, we can't fix it. If we cast
first, we can rely on integer promotion to make the result use the
appropriate size.

Change-Id: I7462e28422456c07f179f94d39c10c408d9bec36
Reviewed-on: https://review.haiku-os.org/c/1623
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Adrien Destugues 2019-07-17 20:24:17 +02:00 committed by waddlesplash
parent fbe53d9249
commit 72bfb14432
8 changed files with 12 additions and 12 deletions

View File

@ -1454,7 +1454,7 @@ cdda_scan_partition(int fd, partition_data* partition, void* _cookie)
uint32 lastTrack = toc->last_track + 1 - toc->first_track; uint32 lastTrack = toc->last_track + 1 - toc->first_track;
scsi_cd_msf& end = toc->tracks[lastTrack].start.time; scsi_cd_msf& end = toc->tracks[lastTrack].start.time;
partition->content_size = off_t(end.minute * kFramesPerMinute partition->content_size = ((off_t)end.minute * kFramesPerMinute
+ end.second * kFramesPerSecond + end.frame) * kFrameSize; + end.second * kFramesPerSecond + end.frame) * kFrameSize;
partition->block_size = kFrameSize; partition->block_size = kFrameSize;

View File

@ -96,9 +96,9 @@ exfat_identify_partition(int fd, partition_data* partition, void** _cookie)
uint32 rootDirCluster = superBlock.RootDirCluster(); uint32 rootDirCluster = superBlock.RootDirCluster();
uint32 blockSize = 1 << superBlock.BlockShift(); uint32 blockSize = 1 << superBlock.BlockShift();
uint32 clusterSize = blockSize << superBlock.BlocksPerClusterShift(); uint32 clusterSize = blockSize << superBlock.BlocksPerClusterShift();
uint64 rootDirectoryOffset = (uint64)(EXFAT_SUPER_BLOCK_OFFSET uint64 rootDirectoryOffset = EXFAT_SUPER_BLOCK_OFFSET
+ superBlock.FirstDataBlock() * blockSize + (uint64)superBlock.FirstDataBlock() * blockSize
+ (rootDirCluster - 2) * clusterSize); + (rootDirCluster - 2) * clusterSize;
struct exfat_entry entry; struct exfat_entry entry;
size_t entrySize = sizeof(struct exfat_entry); size_t entrySize = sizeof(struct exfat_entry);
for (uint32 i = 0; read_pos(fd, rootDirectoryOffset + i * entrySize, for (uint32 i = 0; read_pos(fd, rootDirectoryOffset + i * entrySize,

View File

@ -634,10 +634,10 @@ SonixCamDevice::MinRawFrameSize()
{ {
// if (fCompressionEnabled) { ... return ; } // if (fCompressionEnabled) { ... return ; }
BRect vf(VideoFrame()); BRect vf(VideoFrame());
int w = vf.IntegerWidth()+1; size_t w = vf.IntegerWidth()+1;
int h = vf.IntegerHeight()+1; size_t h = vf.IntegerHeight()+1;
// 1 byte/pixel // 1 byte/pixel
return (size_t)(w*h); return w * h;
} }

View File

@ -1713,7 +1713,7 @@ time_t dos_to_unix_time(dosdatetime)
++days; /* OK through 2199 */ ++days; /* OK through 2199 */
/* convert date & time to seconds relative to 00:00:00, 01/01/YRBASE */ /* convert date & time to seconds relative to 00:00:00, 01/01/YRBASE */
m_time = (time_t)((unsigned long)(days + dy) * 86400L + m_time = (time_t)(((unsigned long)days + dy) * 86400L +
(unsigned long)hh * 3600L + (unsigned long)hh * 3600L +
(unsigned long)(mm * 60 + ss)); (unsigned long)(mm * 60 + ss));
/* - 1; MS-DOS times always rounded up to nearest even second */ /* - 1; MS-DOS times always rounded up to nearest even second */

View File

@ -157,7 +157,7 @@ PackageFileHeapReader::ReadAndDecompressChunk(size_t chunkIndex,
{ {
uint64 offset = fOffsets[chunkIndex]; uint64 offset = fOffsets[chunkIndex];
bool isLastChunk bool isLastChunk
= uint64(chunkIndex + 1) * kChunkSize >= fUncompressedHeapSize; = ((uint64)chunkIndex + 1) * kChunkSize >= fUncompressedHeapSize;
size_t compressedSize = isLastChunk size_t compressedSize = isLastChunk
? fCompressedHeapSize - offset ? fCompressedHeapSize - offset
: fOffsets[chunkIndex + 1] - offset; : fOffsets[chunkIndex + 1] - offset;

View File

@ -1731,7 +1731,7 @@ GenericAttributeText::CommitEditedTextFlavor(BTextView* textView)
switch (type) { switch (type) {
case B_STRING_TYPE: case B_STRING_TYPE:
size = fModel->WriteAttr(columnName, type, 0, textView->Text(), size = fModel->WriteAttr(columnName, type, 0, textView->Text(),
(size_t)(textView->TextLength() + 1)); (size_t)textView->TextLength() + 1);
break; break;
case B_BOOL_TYPE: case B_BOOL_TYPE:

View File

@ -597,7 +597,7 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
if (dstp + 1 + n >= eob) { if (dstp + 1 + n >= eob) {
goto cleanup; goto cleanup;
} }
memcpy(dstp, srcp, (size_t)(n + 1)); memcpy(dstp, srcp, (size_t)n + 1);
srcp += n + 1; srcp += n + 1;
dstp += n + 1; dstp += n + 1;
} while (n != 0); } while (n != 0);

View File

@ -154,7 +154,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen,
addlen((size_t)x, &buf, &buflen); addlen((size_t)x, &buf, &buflen);
len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type))); len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
T(addstr(tmp, (size_t)len, &buf, &buflen)); T(addstr(tmp, (size_t)len, &buf, &buflen));
T(spaced = addtab((size_t)(x + len), (size_t)16, spaced, &buf, &buflen)); T(spaced = addtab((size_t)x + len, (size_t)16, spaced, &buf, &buflen));
/* /*
* RData. * RData.