From 059a6a89caabb86a31f7b97b76b2d408bdb2a442 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Sun, 20 Aug 2023 02:15:22 +0200 Subject: [PATCH] Added NULL checks for the functions dealing with dialogs --- src/backend_helper.c | 17 ++++++++++------- src/print_backend_cups.c | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backend_helper.c b/src/backend_helper.c index 1b6201e..d2eab07 100644 --- a/src/backend_helper.c +++ b/src/backend_helper.c @@ -111,37 +111,37 @@ Dialog *find_dialog(BackendObj *b, const char *dialog_name) int *get_dialog_cancel(BackendObj *b, const char *dialog_name) { Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name)); - return &d->cancel; + return (d ? &d->cancel : NULL); } void set_dialog_cancel(BackendObj *b, const char *dialog_name) { int *x = get_dialog_cancel(b, dialog_name); - *x = 1; + if (x) *x = 1; } void reset_dialog_cancel(BackendObj *b, const char *dialog_name) { int *x = get_dialog_cancel(b, dialog_name); - *x = 0; + if (x) *x = 0; } void set_hide_remote_printers(BackendObj *b, const char *dialog_name) { Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name)); - d->hide_remote = TRUE; + if (d) d->hide_remote = TRUE; } void unset_hide_remote_printers(BackendObj *b, const char *dialog_name) { Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name)); - d->hide_remote = FALSE; + if (d) d->hide_remote = FALSE; } void set_hide_temp_printers(BackendObj *b, const char *dialog_name) { Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name)); - d->hide_temp = TRUE; + if (d) d->hide_temp = TRUE; } void unset_hide_temp_printers(BackendObj *b, const char *dialog_name) { Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name)); - d->hide_temp = FALSE; + if (d) d->hide_temp = FALSE; } static int @@ -451,6 +451,7 @@ void send_printer_state_changed_signal(BackendObj *b, const char *dialog_name, c void notify_removed_printers(BackendObj *b, const char *dialog_name, GHashTable *new_table) { Dialog *d = (Dialog *)g_hash_table_lookup(b->dialogs, dialog_name); + if (!d) return; GHashTable *prev = d->printers; GList *prevlist = g_hash_table_get_keys(prev); @@ -473,6 +474,8 @@ void notify_added_printers(BackendObj *b, const char *dialog_name, GHashTable *n { GHashTableIter iter; Dialog *d = (Dialog *)g_hash_table_lookup(b->dialogs, dialog_name); + if (!d) return; + GHashTable *prev = d->printers; printf("Notifying added printers.\n"); gpointer printer_name; diff --git a/src/print_backend_cups.c b/src/print_backend_cups.c index a1ea05e..12b04c6 100644 --- a/src/print_backend_cups.c +++ b/src/print_backend_cups.c @@ -293,7 +293,7 @@ static void on_stop_backend(GDBusConnection *connection, * Ignore this signal if the dialog's keep_alive variable is set */ Dialog *d = find_dialog(b, sender_name); - if (d->keep_alive) + if (d && d->keep_alive) return; set_dialog_cancel(b, sender_name);