Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: >-
brew install --display-times ${{ env.MAC_PKGS }}
- name: meson
run: meson setup build
run: meson setup -Dsanitize-address=true -Dsanitize-undefined=true build
- name: build
run: meson compile -C build
- name: install
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: meson
run: |
meson --version
meson setup build
meson setup -Dsanitize-address=true -Dsanitize-undefined=true build
env:
CXX: ${{ matrix.compiler }}
- name: build
Expand All @@ -69,7 +69,7 @@ jobs:
run: sudo meson install -C build
- name: test
run: |
xvfb-run -a meson test -C build --verbose --no-stdsplit
ASAN_OPTIONS=detect_leaks=0 xvfb-run -a meson test -C build --verbose --no-stdsplit

codecov:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ if get_option('sanitize-address')
add_project_arguments('-fsanitize=address', language: 'cpp')
add_project_link_arguments('-fsanitize=address', language: 'cpp')
endif
if get_option('sanitize-undefined')
add_project_arguments('-fsanitize=undefined', language: 'cpp')
add_project_link_arguments('-fsanitize=undefined', language: 'cpp')
endif

so_version = 1
subdir('src')
Expand Down
7 changes: 7 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ option(
value: false,
description: 'enable -fsanitize=address compile/link flag',
)

option(
'sanitize-undefined',
type: 'boolean',
value: false,
description: 'enable -fsanitize=undefined compile/link flag',
)
3 changes: 3 additions & 0 deletions src/iptux-core/TransFileModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ std::string TransFileModel::getFinishedLengthText() const {
}

double TransFileModel::getProgress() const {
if (fileLength <= 0) {
return 0.0; // Avoid division by zero
Comment on lines +111 to +112

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Returning 0.0 for non-positive fileLength may mask input errors.

Consider logging a warning if fileLength is negative, as this may signal a logic error.

}
return percent(finishedLength, fileLength);
}

Expand Down
6 changes: 0 additions & 6 deletions src/iptux-core/internal/UdpData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ UdpData::UdpData(CoreThread& coreThread,
}
}

UdpData::UdpData(const string& buf_, const string& ipv4String)
: coreThread(*(CoreThread*)NULL), size(buf_.size()), encode(nullptr) {
this->ipv4 = inAddrFromString(ipv4String);
memcpy(buf, &buf_[0], buf_.size());
}

/**
* 类析构函数.
*/
Expand Down
1 change: 0 additions & 1 deletion src/iptux-core/internal/UdpData.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace iptux {
class UdpData {
public:
UdpData(CoreThread& coreThread, in_addr ipv4, const char buf[], size_t size);
UdpData(const std::string& buf, const std::string& ipv4String);
~UdpData();

in_addr getIpv4() const { return ipv4; }
Expand Down
4 changes: 3 additions & 1 deletion src/iptux-core/internal/UdpDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ using namespace std;
using namespace iptux;

TEST(UdpData, getCommandNo) {
ASSERT_EQ(UdpData("", "127.0.0.1").getCommandNo(), 0);
auto coreThread = newCoreThread();
UdpData data(*coreThread, inAddrFromString("127.0.0.1"), "", 0);
ASSERT_EQ(data.getCommandNo(), 0);
}
4 changes: 2 additions & 2 deletions src/iptux/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ void Application::activate() {
}

void Application::onStartup(Application& self) {
self.data = make_shared<ProgramData>(self.config);
self.cthrd = make_shared<UiCoreThread>(&self, self.data);
init_theme(&self);
iptux_register_resource();
self.menuBuilder =
gtk_builder_new_from_resource(IPTUX_RESOURCE "gtk/menus.ui");
self.data = make_shared<ProgramData>(self.config);
self.logSystem = new LogSystem(self.data);
self.cthrd = make_shared<UiCoreThread>(&self, self.data);
if (self.enable_app_indicator_) {
self.app_indicator = make_shared<IptuxAppIndicator>(&self);
}
Expand Down
12 changes: 6 additions & 6 deletions src/iptux/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@
this->info_style_ = info_style;
}

GtkSortType sort_type =
GtkSortTypeFromStr(this->config->GetString(config_names[CFG_SORT_TYPE]));
if (sort_type != GTK_SORT_TYPE_INVALID) {
GtkSortType sort_type;
if (GtkSortTypeFromStr(this->config->GetString(config_names[CFG_SORT_TYPE]),
sort_type)) {
this->sort_type_ = sort_type;
}

Expand Down Expand Up @@ -1062,10 +1062,10 @@
GVariant* value,
MainWindow& self) {
string sortType = g_variant_get_string(value, nullptr);
GtkSortType sort_type = GtkSortTypeFromStr(sortType);
GtkSortType sort_type;

if (sort_type == GTK_SORT_TYPE_INVALID) {
LOG_WARN("unknown sorttype: %s", sortType.c_str());
if (!GtkSortTypeFromStr(sortType, sort_type)) {
LOG_WARN("unknown sort type: %s", sortType.c_str());

Check warning on line 1068 in src/iptux/MainWindow.cpp

View check run for this annotation

Codecov / codecov/patch

src/iptux/MainWindow.cpp#L1068

Added line #L1068 was not covered by tests
return;
}
self.sort_type_ = sort_type;
Expand Down
2 changes: 2 additions & 0 deletions src/iptux/TestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Application* CreateApplication() {
gtk_init(nullptr, nullptr);
auto config = newTestIptuxConfig();
Application* app = new Application(config);
app->set_enable_app_indicator(false);
app->startup();
// g_application_register(G_APPLICATION(app->getApp()), nullptr, nullptr);
// auto i = g_application_get_is_registered(G_APPLICATION(app->getApp()));
// EXPECT_TRUE(i);
Expand Down
7 changes: 4 additions & 3 deletions src/iptux/UiModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,14 @@ static const char* gtk_sort_type_names[] = {
[GTK_SORT_DESCENDING] = "descending",
};

GtkSortType GtkSortTypeFromStr(const std::string& s) {
bool GtkSortTypeFromStr(const std::string& s, GtkSortType& outType) {
for (int i = GTK_SORT_ASCENDING; i <= GTK_SORT_DESCENDING; ++i) {
if (s == gtk_sort_type_names[i]) {
return (GtkSortType)i;
outType = (GtkSortType)i;
return true;
}
}
return GTK_SORT_TYPE_INVALID;
return false;
}
const char* GtkSortTypeToStr(GtkSortType t) {
if (GTK_SORT_ASCENDING <= t && t <= GTK_SORT_DESCENDING) {
Expand Down
3 changes: 1 addition & 2 deletions src/iptux/UiModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ enum class GroupInfoStyle {
GroupInfoStyle GroupInfoStyleFromStr(const std::string& s);
const char* GroupInfoStyleToStr(GroupInfoStyle style);

const GtkSortType GTK_SORT_TYPE_INVALID = (GtkSortType)-1;
GtkSortType GtkSortTypeFromStr(const std::string& s);
bool GtkSortTypeFromStr(const std::string& s, GtkSortType& outType);
const char* GtkSortTypeToStr(GtkSortType t);

class GroupInfo {
Expand Down
Loading