mirror of
https://github.com/transmission/transmission.git
synced 2025-12-19 18:08:31 +00:00
fix: new warnings (#2270)
* fix: avoid potential resource leak in metainfo test Xref: https://scan5.coverity.com/reports.htm#v48014/p10174/fileInstanceId=205022335&defectInstanceId=52337396&mergedDefectId=1494638 * fix: use-init-statement warning Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX2MsJ_lWODkx6cuASq6&open=AX2MsJ_lWODkx6cuASq6 * fix: omit-redundant-override-specifier warning Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX2MsJ5GWODkx6cuASq5&open=AX2MsJ5GWODkx6cuASq5 * fix: improper-use-of-negative-value warning Xref: https://scan5.coverity.com/reports.htm#v48014/p10174/fileInstanceId=205020121&defectInstanceId=52337394&mergedDefectId=1494639 * fix: unchecked return value warning Xref: https://scan5.coverity.com/reports.htm#v48014/p10174/fileInstanceId=205020168&defectInstanceId=52304887&mergedDefectId=1491438 * fix: potential-divide-by-zero warning Xref: https://scan5.coverity.com/reports.htm#v48014/p10174/fileInstanceId=205020106&defectInstanceId=52337395&mergedDefectId=1494438
This commit is contained in:
@@ -39,7 +39,13 @@ struct tr_block_info
|
||||
|
||||
constexpr tr_piece_index_t pieceForBlock(tr_block_index_t block) const
|
||||
{
|
||||
return n_blocks_in_piece ? block / n_blocks_in_piece : 0;
|
||||
// if not initialized yet, don't divide by zero
|
||||
if (n_blocks_in_piece == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return block / n_blocks_in_piece;
|
||||
}
|
||||
|
||||
constexpr uint32_t pieceSize(tr_piece_index_t piece) const
|
||||
@@ -56,14 +62,36 @@ struct tr_block_info
|
||||
|
||||
constexpr tr_piece_index_t pieceOf(uint64_t offset) const
|
||||
{
|
||||
// if not initialized yet, don't divide by zero
|
||||
if (piece_size == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// handle 0-byte files at the end of a torrent
|
||||
return offset == total_size ? n_pieces - 1 : offset / piece_size;
|
||||
if (offset == total_size)
|
||||
{
|
||||
return n_pieces - 1;
|
||||
}
|
||||
|
||||
return offset / piece_size;
|
||||
}
|
||||
|
||||
constexpr tr_block_index_t blockOf(uint64_t offset) const
|
||||
{
|
||||
// if not initialized yet, don't divide by zero
|
||||
if (block_size == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// handle 0-byte files at the end of a torrent
|
||||
return offset == total_size ? n_blocks - 1 : offset / block_size;
|
||||
if (offset == total_size)
|
||||
{
|
||||
return n_blocks - 1;
|
||||
}
|
||||
|
||||
return offset / block_size;
|
||||
}
|
||||
|
||||
constexpr uint64_t offset(tr_piece_index_t piece, uint32_t offset, uint32_t length = 0) const
|
||||
|
||||
Reference in New Issue
Block a user