1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-22 07:42:37 +00:00

fix: gcc-13 warnings pt. 2 (#6404)

* fix: tr_priority_t usage warnings

* build: disable -Wnull-dereference warnings when building GTest

* fix: -Wunused-result warning in tr_spawn_async()

* fix: -Warray-bounds warning in NetTest::compact4()
This commit is contained in:
Charles Kerr 2023-12-23 10:32:04 -06:00 committed by GitHub
parent a9fa9430ba
commit 581d9c34cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 43 deletions

View file

@ -725,24 +725,25 @@ bool FileList::Impl::onViewPathToggled(Gtk::TreeViewColumn* col, Gtk::TreeModel:
if (cid == file_cols.priority.index()) if (cid == file_cols.priority.index())
{ {
auto priority = iter->get_value(file_cols.priority); auto const old_priority = iter->get_value(file_cols.priority);
auto new_priority = TR_PRI_NORMAL;
switch (priority) switch (old_priority)
{ {
case TR_PRI_NORMAL: case TR_PRI_NORMAL:
priority = TR_PRI_HIGH; new_priority = TR_PRI_HIGH;
break; break;
case TR_PRI_HIGH: case TR_PRI_HIGH:
priority = TR_PRI_LOW; new_priority = TR_PRI_LOW;
break; break;
default: default:
priority = TR_PRI_NORMAL; new_priority = TR_PRI_NORMAL;
break; break;
} }
tr_torrentSetFilePriorities(tor, indexBuf.data(), indexBuf.size(), priority); tr_torrentSetFilePriorities(tor, indexBuf.data(), indexBuf.size(), new_priority);
} }
else else
{ {

View file

@ -118,7 +118,7 @@ void OptionsDialog::Impl::addResponseCB(int response)
{ {
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT)) if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
{ {
tr_torrentSetPriority(tor_, gtr_combo_box_get_active_enum(*priority_combo_)); tr_torrentSetPriority(tor_, static_cast<tr_priority_t>(gtr_combo_box_get_active_enum(*priority_combo_)));
if (run_check_->get_active()) if (run_check_->get_active())
{ {

View file

@ -242,6 +242,7 @@ struct tr_address
} addr; } addr;
static auto constexpr CompactAddrBytes = std::array{ 4U, 16U }; static auto constexpr CompactAddrBytes = std::array{ 4U, 16U };
static auto constexpr CompactAddrMaxBytes = 16U;
static_assert(std::size(CompactAddrBytes) == NUM_TR_AF_INET_TYPES); static_assert(std::size(CompactAddrBytes) == NUM_TR_AF_INET_TYPES);
[[nodiscard]] static auto any(tr_address_type type) noexcept [[nodiscard]] static auto any(tr_address_type type) noexcept

View file

@ -729,9 +729,9 @@ tr_resume::fields_t load_from_file(tr_torrent* tor, tr_torrent::ResumeHelper& he
} }
if ((fields_to_load & tr_resume::BandwidthPriority) != 0 && tr_variantDictFindInt(&top, TR_KEY_bandwidth_priority, &i) && if ((fields_to_load & tr_resume::BandwidthPriority) != 0 && tr_variantDictFindInt(&top, TR_KEY_bandwidth_priority, &i) &&
tr_isPriority(i)) tr_isPriority(static_cast<tr_priority_t>(i)))
{ {
tr_torrentSetPriority(tor, i); tr_torrentSetPriority(tor, static_cast<tr_priority_t>(i));
fields_loaded |= tr_resume::BandwidthPriority; fields_loaded |= tr_resume::BandwidthPriority;
} }

View file

@ -164,8 +164,8 @@ bool tr_spawn_async(
if (!tr_spawn_async_in_child(cmd, env, work_dir)) if (!tr_spawn_async_in_child(cmd, env, work_dir))
{ {
(void)write(pipe_fds[1], &errno, sizeof(errno)); auto const ok = write(pipe_fds[1], &errno, sizeof(errno)) != -1;
_exit(0); _exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
} }
} }

View file

@ -53,8 +53,6 @@ struct tr_torrent;
struct tr_torrent_metainfo; struct tr_torrent_metainfo;
struct tr_variant; struct tr_variant;
using tr_priority_t = int8_t;
#define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id" #define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id"
enum tr_verify_added_mode enum tr_verify_added_mode
@ -74,6 +72,13 @@ enum tr_encryption_mode
TR_ENCRYPTION_REQUIRED TR_ENCRYPTION_REQUIRED
}; };
enum tr_priority_t : int8_t
{
TR_PRI_LOW = -1,
TR_PRI_NORMAL = 0, /* since Normal is 0, memset initializes nicely */
TR_PRI_HIGH = 1
};
#define TR_RATIO_NA (-1) #define TR_RATIO_NA (-1)
#define TR_RATIO_INF (-2) #define TR_RATIO_INF (-2)
@ -1010,13 +1015,6 @@ void tr_torrentSetPeerLimit(tr_torrent* tor, uint16_t max_connected_peers);
// --- File Priorities // --- File Priorities
enum : tr_priority_t
{
TR_PRI_LOW = -1,
TR_PRI_NORMAL = 0, /* since Normal is 0, memset initializes nicely */
TR_PRI_HIGH = 1
};
/** /**
* @brief Set a batch of files to a particular priority. * @brief Set a batch of files to a particular priority.
* *

View file

@ -47,7 +47,7 @@ static CGFloat const kImageOverlap = 1.0;
[super setSelected:flag forSegment:segment]; [super setSelected:flag forSegment:segment];
//only for when clicking manually //only for when clicking manually
NSInteger priority; tr_priority_t priority;
switch (segment) switch (segment)
{ {
case 0: case 0:

View file

@ -2,6 +2,14 @@ set(GTEST_ROOT_DIR ${TR_THIRD_PARTY_SOURCE_DIR}/googletest/googletest)
add_library(gtestall STATIC) add_library(gtestall STATIC)
# GTest 1.12 triggers nullptr warnings in gcc 13
set(CACHE_ID "${CMAKE_CXX_COMPILER_ID}_CXX_HAS-Wnull-dereference")
string(TOLOWER "${CACHE_ID}" CACHE_ID)
check_c_compiler_flag(-Wnull-dereference ${CACHE_ID})
if(${CACHE_ID})
target_compile_options(gtestall PRIVATE -Wno-null-dereference)
endif()
target_sources(gtestall target_sources(gtestall
PRIVATE PRIVATE
${GTEST_ROOT_DIR}/src/gtest-all.cc ${GTEST_ROOT_DIR}/src/gtest-all.cc

View file

@ -71,49 +71,47 @@ TEST_F(NetTest, compact4)
EXPECT_EQ(ExpectedPort, port); EXPECT_EQ(ExpectedPort, port);
// ...serialize it back again // ...serialize it back again
auto compact4 = std::array<std::byte, Compact4Bytes>{}; auto buf = std::array<std::byte, tr_address::CompactAddrMaxBytes>{};
auto out = std::data(compact4); auto out = std::data(buf);
out = socket_address.to_compact(out); out = socket_address.to_compact(out);
EXPECT_EQ(std::size(Compact4), static_cast<size_t>(out - std::data(compact4))); EXPECT_EQ(std::size(Compact4), static_cast<size_t>(out - std::data(buf)));
EXPECT_EQ(Compact4, compact4); EXPECT_TRUE(std::equal(std::begin(Compact4), std::end(Compact4), std::data(buf)));
/// tr_address --> compact /// tr_address --> compact
compact4.fill(std::byte{}); buf.fill(std::byte{});
out = std::data(compact4); out = std::data(buf);
out = addr.to_compact(out); out = addr.to_compact(out);
EXPECT_EQ(std::size(Compact4) - tr_port::CompactPortBytes, static_cast<size_t>(out - std::data(compact4))); EXPECT_EQ(std::size(Compact4) - tr_port::CompactPortBytes, static_cast<size_t>(out - std::data(buf)));
EXPECT_TRUE(std::equal( EXPECT_TRUE(
std::data(Compact4), std::equal(std::data(Compact4), std::data(Compact4) + std::size(Compact4) - tr_port::CompactPortBytes, std::data(buf)));
std::data(Compact4) + std::size(Compact4) - tr_port::CompactPortBytes,
std::data(compact4)));
EXPECT_TRUE(std::all_of( EXPECT_TRUE(std::all_of(
std::begin(compact4) + std::size(Compact4) - tr_port::CompactPortBytes, std::begin(buf) + std::size(Compact4) - tr_port::CompactPortBytes,
std::end(compact4), std::end(buf),
[](std::byte const& byte) { return static_cast<unsigned char>(byte) == 0U; })); [](std::byte const& byte) { return static_cast<unsigned char>(byte) == 0U; }));
/// sockaddr --> compact /// sockaddr --> compact
auto [ss, sslen] = socket_address.to_sockaddr(); auto [ss, sslen] = socket_address.to_sockaddr();
compact4.fill(std::byte{}); buf.fill(std::byte{});
out = std::data(compact4); out = std::data(buf);
out = tr_socket_address::to_compact(out, &ss); out = tr_socket_address::to_compact(out, &ss);
EXPECT_EQ(out, std::data(compact4) + std::size(compact4)); EXPECT_EQ(std::size(Compact4), static_cast<size_t>(out - std::data(buf)));
EXPECT_EQ(Compact4, compact4); EXPECT_TRUE(std::equal(std::begin(Compact4), std::end(Compact4), std::data(buf)));
/// compact <--> tr_pex /// compact <--> tr_pex
// extract them into a tr_pex struct... // extract them into a tr_pex struct...
auto const pex = tr_pex::from_compact_ipv4(std::data(compact4), std::size(compact4), nullptr, 0U); auto const pex = tr_pex::from_compact_ipv4(std::data(buf), out - std::data(buf), nullptr, 0U);
ASSERT_EQ(1U, std::size(pex)); ASSERT_EQ(1U, std::size(pex));
EXPECT_EQ(addr, pex.front().socket_address.address()); EXPECT_EQ(addr, pex.front().socket_address.address());
EXPECT_EQ(port, pex.front().socket_address.port()); EXPECT_EQ(port, pex.front().socket_address.port());
// ...serialize that back again too // ...serialize that back again too
std::fill(std::begin(compact4), std::end(compact4), std::byte{}); buf.fill(std::byte{});
out = std::data(compact4); out = std::data(buf);
out = tr_pex::to_compact(out, std::data(pex), std::size(pex)); out = tr_pex::to_compact(out, std::data(pex), std::size(pex));
EXPECT_EQ(std::data(compact4) + std::size(compact4), out); EXPECT_EQ(std::size(Compact4), static_cast<size_t>(out - std::data(buf)));
EXPECT_EQ(Compact4, compact4); EXPECT_TRUE(std::equal(std::begin(Compact4), std::end(Compact4), std::data(buf)));
} }
TEST_F(NetTest, compact6) TEST_F(NetTest, compact6)