fix: crash during backup - GTK assertions and segfault

- Fix gtk_box_pack on GtkMenuBar (was treated as GtkBox): build_toolbar() now returns widget instead of packing into toolbar_ member
- Fix markup error: </big></big> -> </big></b> in backup window header
- Fix segfault: validate tag name against TextBuffer tag table before use
- Add missing 'cmd' tag to live log buffer
- Add NULL sentinel to gtk_text_buffer_insert_with_tags_by_name calls
This commit is contained in:
x3
2026-09-08 08:59:46 +00:00
parent c32b30d5ce
commit 01b03f8424
2 changed files with 12 additions and 10 deletions
+11 -9
View File
@@ -162,8 +162,9 @@ void MainWindow::build_ui() {
gtk_container_add(GTK_CONTAINER(window_), vbox);
build_menu();
build_toolbar();
GtkWidget* btn_toolbar = build_toolbar();
gtk_box_pack_start(GTK_BOX(vbox), toolbar_, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), btn_toolbar, FALSE, FALSE, 0);
GtkWidget* paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start(GTK_BOX(vbox), paned, TRUE, TRUE, 0);
@@ -288,6 +289,7 @@ void MainWindow::build_ui() {
gtk_text_buffer_create_tag(live_buf, "error", "foreground", "#e74c3c", nullptr);
gtk_text_buffer_create_tag(live_buf, "success", "foreground", "#2ecc71", nullptr);
gtk_text_buffer_create_tag(live_buf, "info", "foreground", "#3498db", nullptr);
gtk_text_buffer_create_tag(live_buf, "cmd", "foreground", "#95a5a6", "style", PANGO_STYLE_ITALIC, nullptr);
gtk_container_add(GTK_CONTAINER(live_scroll), live_log_textview_);
gtk_box_pack_start(GTK_BOX(live_box), live_scroll, TRUE, TRUE, 0);
@@ -438,7 +440,7 @@ void MainWindow::build_menu() {
gtk_menu_shell_append(GTK_MENU_SHELL(toolbar_), help_item);
}
void MainWindow::build_toolbar() {
GtkWidget* MainWindow::build_toolbar() {
GtkWidget* tbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
gtk_widget_set_margin_start(tbar, 6);
gtk_widget_set_margin_end(tbar, 6);
@@ -457,7 +459,7 @@ void MainWindow::build_toolbar() {
gtk_box_pack_start(GTK_BOX(tbar), gtk_separator_new(GTK_ORIENTATION_VERTICAL), FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(tbar), mkbtn("Settings", G_CALLBACK(on_settings), this), FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(toolbar_), tbar, FALSE, FALSE, 0);
return tbar;
}
void MainWindow::build_statusbar() {
@@ -748,7 +750,7 @@ void MainWindow::open_backup_window(const std::string& description) {
std::string title_text = description.empty() ? "Creating Backup..." : description;
GtkWidget* hdr_title = gtk_label_new(nullptr);
char title_markup[512];
snprintf(title_markup, sizeof(title_markup), "<b><big>%s</big></big>", title_text.c_str());
snprintf(title_markup, sizeof(title_markup), "<b><big>%s</big></b>", title_text.c_str());
gtk_label_set_markup(GTK_LABEL(hdr_title), title_markup);
gtk_widget_set_halign(hdr_title, GTK_ALIGN_START);
gtk_box_pack_start(GTK_BOX(hdr_vbox), hdr_title, FALSE, FALSE, 0);
@@ -861,8 +863,8 @@ void MainWindow::append_backup_line(const std::string& line, const char* tag) {
GtkTextBuffer* buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(backup_output_view_));
GtkTextIter end;
gtk_text_buffer_get_end_iter(buf, &end);
if (tag) {
gtk_text_buffer_insert_with_tags_by_name(buf, &end, line.c_str(), -1, tag);
if (tag && gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buf), tag)) {
gtk_text_buffer_insert_with_tags_by_name(buf, &end, line.c_str(), -1, tag, nullptr);
} else {
gtk_text_buffer_insert(buf, &end, line.c_str(), -1);
}
@@ -1128,8 +1130,8 @@ void MainWindow::append_live_log(const std::string& line, const char* tag) {
GtkTextBuffer* buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(live_log_textview_));
GtkTextIter end;
gtk_text_buffer_get_end_iter(buf, &end);
if (tag) {
gtk_text_buffer_insert_with_tags_by_name(buf, &end, line.c_str(), -1, tag);
if (tag && gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buf), tag)) {
gtk_text_buffer_insert_with_tags_by_name(buf, &end, line.c_str(), -1, tag, nullptr);
} else {
gtk_text_buffer_insert(buf, &end, line.c_str(), -1);
}
@@ -1165,7 +1167,7 @@ void MainWindow::load_log_history() {
tag = "info";
if (tag) {
gtk_text_buffer_insert_with_tags_by_name(buf, &end, line.c_str(), -1, tag);
gtk_text_buffer_insert_with_tags_by_name(buf, &end, line.c_str(), -1, tag, nullptr);
} else {
gtk_text_buffer_insert(buf, &end, line.c_str(), -1);
}
+1 -1
View File
@@ -27,7 +27,7 @@ public:
private:
void build_ui();
void build_menu();
void build_toolbar();
GtkWidget* build_toolbar();
void build_statusbar();
void refresh_snapshot_list();