From 586a9eb862b04652cca58a3fe0f60758efa5f923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Sun, 5 Nov 2023 16:06:24 +0100 Subject: [PATCH] fix: Implicit conversion loses integer precision (#4919) --- macosx/Controller.mm | 2 +- macosx/PiecesView.mm | 14 +++++++------- macosx/ProgressBarView.mm | 4 ++-- macosx/Torrent.h | 4 ++-- macosx/Torrent.mm | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 1229d81a5..8e22f77a2 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -203,7 +203,7 @@ static void removeKeRangerRansomware() pid_t const krProcessId = [line substringFromIndex:1].intValue; if (kill(krProcessId, SIGKILL) == -1) { - NSLog(@"Unable to forcibly terminate ransomware process (kernel_service, pid %d), please do so manually", (int)krProcessId); + NSLog(@"Unable to forcibly terminate ransomware process (kernel_service, pid %d), please do so manually", krProcessId); } } } diff --git a/macosx/PiecesView.mm b/macosx/PiecesView.mm index 8d695e787..40c1fc58f 100644 --- a/macosx/PiecesView.mm +++ b/macosx/PiecesView.mm @@ -151,22 +151,22 @@ typedef struct PieceInfo // get the current state BOOL const showAvailability = [NSUserDefaults.standardUserDefaults boolForKey:@"PiecesViewShowAvailability"]; - NSInteger const numCells = MIN(_torrent.pieceCount, kMaxCells); + int const numCells = static_cast(MIN(_torrent.pieceCount, kMaxCells)); PieceInfo info; [self.torrent getAvailability:info.available size:numCells]; [self.torrent getAmountFinished:info.complete size:numCells]; // compute bounds and color of each cell - NSInteger const across = (NSInteger)ceil(sqrt(numCells)); + int const across = static_cast(ceil(sqrt(numCells))); CGFloat const fullWidth = self.bounds.size.width; NSInteger const cellWidth = (NSInteger)((fullWidth - (across + 1) * kBetweenPadding) / across); NSInteger const extraBorder = (NSInteger)((fullWidth - ((cellWidth + kBetweenPadding) * across + kBetweenPadding)) / 2); NSMutableArray* cellBounds = [NSMutableArray arrayWithCapacity:numCells]; NSMutableArray* cellColors = [NSMutableArray arrayWithCapacity:numCells]; - for (NSInteger index = 0; index < numCells; index++) + for (int index = 0; index < numCells; index++) { - NSInteger const row = index / across; - NSInteger const col = index % across; + int const row = index / across; + int const col = index % across; cellBounds[index] = [NSValue valueWithRect:NSMakeRect( col * (cellWidth + kBetweenPadding) + kBetweenPadding + extraBorder, @@ -184,12 +184,12 @@ typedef struct PieceInfo { self.image = [NSImage imageWithSize:self.bounds.size flipped:NO drawingHandler:^BOOL(NSRect /*dstRect*/) { NSRect cFillRects[numCells]; - for (NSInteger i = 0; i < numCells; ++i) + for (int i = 0; i < numCells; ++i) { cFillRects[i] = cellBounds[i].rectValue; } NSColor* cFillColors[numCells]; - for (NSInteger i = 0; i < numCells; ++i) + for (int i = 0; i < numCells; ++i) { cFillColors[i] = cellColors[i]; } diff --git a/macosx/ProgressBarView.mm b/macosx/ProgressBarView.mm index ef81a7184..f180ad1e2 100644 --- a/macosx/ProgressBarView.mm +++ b/macosx/ProgressBarView.mm @@ -150,7 +150,7 @@ static NSInteger const kMaxPieces = 18 * 18; return; } - NSInteger pieceCount = MIN(torrent.pieceCount, kMaxPieces); + int const pieceCount = static_cast(MIN(torrent.pieceCount, kMaxPieces)); float* piecesPercent = static_cast(malloc(pieceCount * sizeof(float))); [torrent getAmountFinished:piecesPercent size:pieceCount]; @@ -166,7 +166,7 @@ static NSInteger const kMaxPieces = 18 * 18; NSIndexSet* previousFinishedIndexes = torrent.previousFinishedPieces; NSMutableIndexSet* finishedIndexes = [NSMutableIndexSet indexSet]; - for (NSInteger i = 0; i < pieceCount; i++) + for (int i = 0; i < pieceCount; i++) { NSColor* pieceColor; if (piecesPercent[i] == 1.0f) diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 6156c9fb3..7ee782509 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -31,8 +31,8 @@ extern NSString* const kTorrentDidChangeGroupNotification; @property(nonatomic, readonly) NSString* currentDirectory; -- (void)getAvailability:(int8_t*)tab size:(NSInteger)size; -- (void)getAmountFinished:(float*)tab size:(NSInteger)size; +- (void)getAvailability:(int8_t*)tab size:(int)size; +- (void)getAmountFinished:(float*)tab size:(int)size; @property(nonatomic) NSIndexSet* previousFinishedPieces; - (void)update; diff --git a/macosx/Torrent.mm b/macosx/Torrent.mm index ff9aeaf17..f5abc9af4 100644 --- a/macosx/Torrent.mm +++ b/macosx/Torrent.mm @@ -201,12 +201,12 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error) return @(tr_torrentGetCurrentDir(self.fHandle)); } -- (void)getAvailability:(int8_t*)tab size:(NSInteger)size +- (void)getAvailability:(int8_t*)tab size:(int)size { tr_torrentAvailability(self.fHandle, tab, size); } -- (void)getAmountFinished:(float*)tab size:(NSInteger)size +- (void)getAmountFinished:(float*)tab size:(int)size { tr_torrentAmountFinished(self.fHandle, tab, size); }