Skip to content

Commit

Permalink
Added NULL checks for the functions dealing with dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkamppeter committed Aug 20, 2023
1 parent 879877a commit 059a6a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/backend_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/print_backend_cups.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 059a6a8

Please sign in to comment.