fix: implicit conversion loses integer precision (#6466)

This commit is contained in:
Cœur
2023-12-31 21:04:26 +01:00
committed by GitHub
parent 9c4d28dd08
commit e5e768e2ab
7 changed files with 10 additions and 10 deletions

View File

@@ -19,8 +19,8 @@ void tr_block_info::init_sizes(uint64_t const total_size_in, uint32_t const piec
total_size_ = total_size_in; total_size_ = total_size_in;
piece_size_ = piece_size_in; piece_size_ = piece_size_in;
n_pieces_ = (total_size_ + piece_size_ - 1) / piece_size_; n_pieces_ = static_cast<tr_piece_index_t>((total_size_ + piece_size_ - 1) / piece_size_);
n_blocks_ = (total_size_ + BlockSize - 1) / BlockSize; n_blocks_ = static_cast<tr_block_index_t>((total_size_ + BlockSize - 1) / BlockSize);
uint32_t remainder = total_size_ % piece_size_; uint32_t remainder = total_size_ % piece_size_;
final_piece_size_ = remainder != 0U ? remainder : piece_size_; final_piece_size_ = remainder != 0U ? remainder : piece_size_;

View File

@@ -88,8 +88,8 @@ public:
} }
else else
{ {
loc.block = byte_idx / BlockSize; loc.block = static_cast<tr_block_index_t>(byte_idx / BlockSize);
loc.piece = byte_idx / piece_size(); loc.piece = static_cast<tr_piece_index_t>(byte_idx / piece_size());
} }
loc.block_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.block } * BlockSize)); loc.block_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.block } * BlockSize));

View File

@@ -40,7 +40,7 @@ namespace
return var != nullptr && (var->holds_alternative<tr_variant::Vector>() || var->holds_alternative<tr_variant::Map>()); return var != nullptr && (var->holds_alternative<tr_variant::Vector>() || var->holds_alternative<tr_variant::Map>());
} }
[[nodiscard]] constexpr int variant_index(tr_variant const* const var) [[nodiscard]] constexpr size_t variant_index(tr_variant const* const var)
{ {
if (var != nullptr) if (var != nullptr)
{ {

View File

@@ -30,7 +30,7 @@
struct tr_variant struct tr_variant
{ {
public: public:
enum Type enum Type : size_t
{ {
NoneIndex = 0, NoneIndex = 0,
BoolIndex = 1, BoolIndex = 1,

View File

@@ -899,7 +899,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
//registering the Web UI to Bonjour //registering the Web UI to Bonjour
if ([self.fDefaults boolForKey:@"RPC"] && [self.fDefaults boolForKey:@"RPCWebDiscovery"]) if ([self.fDefaults boolForKey:@"RPC"] && [self.fDefaults boolForKey:@"RPCWebDiscovery"])
{ {
[BonjourController.defaultController startWithPort:[self.fDefaults integerForKey:@"RPCPort"]]; [BonjourController.defaultController startWithPort:static_cast<int>([self.fDefaults integerForKey:@"RPCPort"])];
} }
//shamelessly ask for donations //shamelessly ask for donations

View File

@@ -791,7 +791,7 @@ static NSString* const kWebUIURLFormat = @"http://localhost:%ld/";
return static_cast<int>(components.hour * 60 + components.minute); return static_cast<int>(components.hour * 60 + components.minute);
} }
+ (NSDate*)timeSumToDate:(int)sum + (NSDate*)timeSumToDate:(NSInteger)sum
{ {
NSDateComponents* comps = [[NSDateComponents alloc] init]; NSDateComponents* comps = [[NSDateComponents alloc] init];
comps.hour = sum / 60; comps.hour = sum / 60;
@@ -1515,7 +1515,7 @@ static NSString* const kWebUIURLFormat = @"http://localhost:%ld/";
self.fQueueSeedField.integerValue = seedQueueNum; self.fQueueSeedField.integerValue = seedQueueNum;
//check stalled handled by bindings //check stalled handled by bindings
self.fStalledField.intValue = stalledMinutes; self.fStalledField.integerValue = stalledMinutes;
} }
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil]; [NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];

View File

@@ -88,7 +88,7 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error)
NSError* localError; NSError* localError;
if (![Torrent trashFile:@(filename) error:&localError]) if (![Torrent trashFile:@(filename) error:&localError])
{ {
error->set(localError.code, localError.description.UTF8String); error->set(static_cast<int>(localError.code), localError.description.UTF8String);
return false; return false;
} }
} }