Skip to content

Commit 97dcb4d

Browse files
gtkui: eliminate unsafe conf_get_*** calls in prefwin
1 parent f817e6b commit 97dcb4d

5 files changed

Lines changed: 118 additions & 62 deletions

File tree

plugins/gtkui/prefwin/prefwinappearance.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ prefwin_init_appearance_tab(GtkWidget *_prefwin) {
5252
GtkStyle *style = gtk_widget_get_style (mainwin);
5353
const char *gtk_style_font = pango_font_description_to_string (style->font_desc);
5454

55-
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "tabstrip_text_font")), deadbeef->conf_get_str_fast ("gtkui.font.tabstrip_text", gtk_style_font));
55+
{
56+
char tabstrip_text_font[100];
57+
deadbeef->conf_get_str ("gtkui.font.tabstrip_text", gtk_style_font, tabstrip_text_font, sizeof(tabstrip_text_font));
58+
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "tabstrip_text_font")), tabstrip_text_font);
59+
}
5660

5761
// override listview colors
5862
override = deadbeef->conf_get_int ("gtkui.override_listview_colors", 0);
@@ -65,9 +69,15 @@ prefwin_init_appearance_tab(GtkWidget *_prefwin) {
6569
prefwin_set_toggle_button("listview_playing_text_bold", deadbeef->conf_get_int ("gtkui.embolden_current_track", 0));
6670
prefwin_set_toggle_button("listview_playing_text_italic", deadbeef->conf_get_int ("gtkui.italic_current_track", 0));
6771

68-
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "listview_text_font")), deadbeef->conf_get_str_fast ("gtkui.font.listview_text", gtk_style_font));
69-
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "listview_group_text_font")), deadbeef->conf_get_str_fast ("gtkui.font.listview_group_text", gtk_style_font));
70-
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "listview_column_text_font")), deadbeef->conf_get_str_fast ("gtkui.font.listview_column_text", gtk_style_font));
72+
{
73+
char font_name[100];
74+
deadbeef->conf_get_str ("gtkui.font.listview_text", gtk_style_font, font_name, sizeof (font_name));
75+
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "listview_text_font")), font_name);
76+
deadbeef->conf_get_str ("gtkui.font.listview_group_text", gtk_style_font, font_name, sizeof (font_name));
77+
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "listview_group_text_font")), font_name);
78+
deadbeef->conf_get_str ("gtkui.font.listview_column_text", gtk_style_font, font_name, sizeof (font_name));
79+
gtk_font_button_set_font_name (GTK_FONT_BUTTON (lookup_widget (w, "listview_column_text_font")), font_name);
80+
}
7181

7282
// visualizations
7383
override = deadbeef->conf_get_int ("gtkui.vis.use_custom_base_color", 0);

plugins/gtkui/prefwin/prefwinmisc.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ prefwin_init_gui_misc_tab (GtkWidget *_prefwin) {
9595

9696
gtk_spin_button_set_value(GTK_SPIN_BUTTON (lookup_widget (w, "listview_group_spacing")), deadbeef->conf_get_int ("playlist.groups.spacing", 0));
9797

98-
// fill gui plugin list
99-
GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (w, "gui_plugin"));
100-
const char **names = deadbeef->plug_get_gui_names ();
101-
for (int i = 0; names[i]; i++) {
102-
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), names[i]);
103-
if (!strcmp (names[i], deadbeef->conf_get_str_fast ("gui_plugin", "GTK3"))) {
104-
prefwin_set_combobox (combobox, i);
98+
{
99+
char gui_plugin[100];
100+
deadbeef->conf_get_str ("gui_plugin", "GTK3", gui_plugin, sizeof (gui_plugin));
101+
// fill gui plugin list
102+
GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (w, "gui_plugin"));
103+
const char **names = deadbeef->plug_get_gui_names ();
104+
for (int i = 0; names[i]; i++) {
105+
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), names[i]);
106+
if (!strcmp (names[i], gui_plugin)) {
107+
prefwin_set_combobox (combobox, i);
108+
}
105109
}
106110
}
107111

plugins/gtkui/prefwin/prefwinnetwork.c

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,53 @@ prefwin_init_network_tab (GtkWidget *_prefwin) {
3838
GtkWidget *w = _prefwin;
3939

4040
prefwin_set_toggle_button("pref_network_enableproxy", deadbeef->conf_get_int ("network.proxy", 0));
41-
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyaddress")), deadbeef->conf_get_str_fast ("network.proxy.address", ""));
42-
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyport")), deadbeef->conf_get_str_fast ("network.proxy.port", "8080"));
43-
GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (w, "pref_network_proxytype"));
44-
const char *type = deadbeef->conf_get_str_fast ("network.proxy.type", "HTTP");
45-
if (!strcasecmp (type, "HTTP")) {
46-
prefwin_set_combobox (combobox, 0);
47-
}
48-
else if (!strcasecmp (type, "HTTP_1_0")) {
49-
prefwin_set_combobox (combobox, 1);
41+
{
42+
size_t size = 1000;
43+
char *address = calloc (size, 1);
44+
deadbeef->conf_get_str ("network.proxy.address", "", address, (int)size);
45+
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyaddress")), address);
46+
free (address);
47+
address = NULL;
5048
}
51-
else if (!strcasecmp (type, "SOCKS4")) {
52-
prefwin_set_combobox (combobox, 2);
49+
{
50+
char port[100];
51+
deadbeef->conf_get_str ("network.proxy.port", "8080", port, sizeof (port));
52+
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_network_proxyport")), port);
5353
}
54-
else if (!strcasecmp (type, "SOCKS5")) {
55-
prefwin_set_combobox (combobox, 3);
54+
GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (w, "pref_network_proxytype"));
55+
{
56+
char type[100];
57+
deadbeef->conf_get_str ("network.proxy.type", "HTTP", type, sizeof (type));
58+
if (!strcasecmp (type, "HTTP")) {
59+
prefwin_set_combobox (combobox, 0);
60+
}
61+
else if (!strcasecmp (type, "HTTP_1_0")) {
62+
prefwin_set_combobox (combobox, 1);
63+
}
64+
else if (!strcasecmp (type, "SOCKS4")) {
65+
prefwin_set_combobox (combobox, 2);
66+
}
67+
else if (!strcasecmp (type, "SOCKS5")) {
68+
prefwin_set_combobox (combobox, 3);
69+
}
70+
else if (!strcasecmp (type, "SOCKS4A")) {
71+
prefwin_set_combobox (combobox, 4);
72+
}
73+
else if (!strcasecmp (type, "SOCKS5_HOSTNAME")) {
74+
prefwin_set_combobox (combobox, 5);
75+
}
5676
}
57-
else if (!strcasecmp (type, "SOCKS4A")) {
58-
prefwin_set_combobox (combobox, 4);
77+
78+
{
79+
char username[100];
80+
deadbeef->conf_get_str ("network.proxy.username", "", username, sizeof (username));
81+
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxyuser")), username);
5982
}
60-
else if (!strcasecmp (type, "SOCKS5_HOSTNAME")) {
61-
prefwin_set_combobox (combobox, 5);
83+
{
84+
char password[100];
85+
deadbeef->conf_get_str ("network.proxy.password", "", password, sizeof (password));
86+
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxypassword")), password);
6287
}
63-
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxyuser")), deadbeef->conf_get_str_fast ("network.proxy.username", ""));
64-
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "proxypassword")), deadbeef->conf_get_str_fast ("network.proxy.password", ""));
6588

6689
char ua[100];
6790
deadbeef->conf_get_str ("network.http_user_agent", "deadbeef", ua, sizeof (ua));

plugins/gtkui/prefwin/prefwinplayback.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include <gtk/gtk.h>
25+
#include <stdlib.h>
2526
#include "../gtkui.h"
2627
#include "../support.h"
2728
#include "prefwin.h"
@@ -61,7 +62,14 @@ prefwin_init_playback_tab (GtkWidget *_prefwin) {
6162
int active = deadbeef->conf_get_int ("cli_add_to_specific_playlist", 1);
6263
prefwin_set_toggle_button("cli_add_to_playlist", active);
6364
gtk_widget_set_sensitive (lookup_widget (w, "cli_playlist_name"), active);
64-
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "cli_playlist_name")), deadbeef->conf_get_str_fast ("cli_add_playlist_name", "Default"));
65+
66+
{
67+
size_t size = 1000;
68+
char *playlist_name = calloc(size, 1);
69+
deadbeef->conf_get_str ("cli_add_playlist_name", "Default", playlist_name, (int)size);
70+
gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "cli_playlist_name")), playlist_name);
71+
free (playlist_name);
72+
}
6573

6674
// resume last session
6775
prefwin_set_toggle_button("resume_last_session", deadbeef->conf_get_int ("resume_last_session", 1));

plugins/gtkui/prefwin/prefwinsound.c

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ gtk_enum_sound_callback (const char *name, const char *desc, void *userdata) {
4747
GtkComboBox *combobox = GTK_COMBO_BOX (userdata);
4848
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), desc);
4949

50-
deadbeef->conf_lock ();
51-
const char *curr = deadbeef->conf_get_str_fast (_get_output_soundcard_conf_name(), "default");
52-
if (!strcmp (curr, name)) {
53-
gtk_combo_box_set_active (combobox, g_slist_length (output_device_names));
50+
{
51+
char soundcard_name[100];
52+
deadbeef->conf_get_str (_get_output_soundcard_conf_name(), "default", soundcard_name, sizeof (soundcard_name));
53+
if (!strcmp (soundcard_name, name)) {
54+
gtk_combo_box_set_active (combobox, g_slist_length (output_device_names));
55+
}
5456
}
55-
deadbeef->conf_unlock ();
5657

5758
output_device_names = g_slist_append (output_device_names, g_strdup (name));
5859
}
@@ -68,12 +69,13 @@ prefwin_fill_soundcards (void) {
6869

6970
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), _("Default Audio Device"));
7071

71-
deadbeef->conf_lock ();
72-
const char *s = deadbeef->conf_get_str_fast (_get_output_soundcard_conf_name(), "default");
73-
if (!strcmp (s, "default")) {
74-
gtk_combo_box_set_active (combobox, 0);
72+
{
73+
char soundcard_name[100];
74+
deadbeef->conf_get_str (_get_output_soundcard_conf_name(), "default", soundcard_name, sizeof (soundcard_name));
75+
if (!strcmp (soundcard_name, "default")) {
76+
gtk_combo_box_set_active (combobox, 0);
77+
}
7578
}
76-
deadbeef->conf_unlock ();
7779

7880
if (output_device_names) {
7981
for (GSList *dev = output_device_names; dev; dev = dev->next) {
@@ -103,17 +105,18 @@ on_pref_output_plugin_changed (GtkComboBox *combobox,
103105
DB_output_t *prev = NULL;
104106
DB_output_t *new = NULL;
105107

106-
deadbeef->conf_lock ();
107-
const char *outplugname = deadbeef->conf_get_str_fast ("output_plugin", "alsa");
108-
for (int i = 0; out_plugs[i]; i++) {
109-
if (!strcmp (out_plugs[i]->plugin.id, outplugname)) {
110-
prev = out_plugs[i];
111-
}
112-
if (i == active) {
113-
new = out_plugs[i];
108+
{
109+
char outplugname[100];
110+
deadbeef->conf_get_str ("output_plugin", "alsa", outplugname, sizeof (outplugname));
111+
for (int i = 0; out_plugs[i]; i++) {
112+
if (!strcmp (out_plugs[i]->plugin.id, outplugname)) {
113+
prev = out_plugs[i];
114+
}
115+
if (i == active) {
116+
new = out_plugs[i];
117+
}
114118
}
115119
}
116-
deadbeef->conf_unlock ();
117120

118121
if (!new) {
119122
fprintf (stderr, "failed to find output plugin selected in preferences window\n");
@@ -132,14 +135,13 @@ on_pref_soundcard_changed (GtkComboBox *combobox,
132135
{
133136
int active = gtk_combo_box_get_active (combobox);
134137
if (active >= 0 && active < g_slist_length(output_device_names)) {
135-
deadbeef->conf_lock ();
136-
const char *soundcard = deadbeef->conf_get_str_fast (_get_output_soundcard_conf_name(), "default");
138+
char soundcard[100];
139+
deadbeef->conf_get_str (_get_output_soundcard_conf_name(), "default", soundcard, sizeof (soundcard));
137140
const char *active_name = g_slist_nth_data (output_device_names, active);
138141
if (strcmp (soundcard, active_name)) {
139142
deadbeef->conf_set_str (_get_output_soundcard_conf_name(), active_name);
140143
deadbeef->sendmessage (DB_EV_CONFIGCHANGED, 0, 0, 0);
141144
}
142-
deadbeef->conf_unlock ();
143145
}
144146
}
145147

@@ -224,12 +226,15 @@ prefwin_init_sound_tab (GtkWidget *_prefwin) {
224226
GtkWidget *w = prefwin = _prefwin;
225227
GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (w, "pref_output_plugin"));
226228

227-
const char *outplugname = deadbeef->conf_get_str_fast ("output_plugin", "alsa");
228-
DB_output_t **out_plugs = deadbeef->plug_get_output_list ();
229-
for (int i = 0; out_plugs[i]; i++) {
230-
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), out_plugs[i]->plugin.name);
231-
if (!strcmp (outplugname, out_plugs[i]->plugin.id)) {
232-
gtk_combo_box_set_active (combobox, i);
229+
{
230+
char outplugname[100];
231+
deadbeef->conf_get_str ("output_plugin", "alsa", outplugname, sizeof(outplugname));
232+
DB_output_t **out_plugs = deadbeef->plug_get_output_list ();
233+
for (int i = 0; out_plugs[i]; i++) {
234+
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combobox), out_plugs[i]->plugin.name);
235+
if (!strcmp (outplugname, out_plugs[i]->plugin.id)) {
236+
gtk_combo_box_set_active (combobox, i);
237+
}
233238
}
234239
}
235240

@@ -263,9 +268,15 @@ prefwin_init_sound_tab (GtkWidget *_prefwin) {
263268
prefwin_set_toggle_button ("checkbutton_dependent_sr", use_dependent_samplerate);
264269

265270
// direct samplerate value
266-
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup_widget (w, "comboboxentry_direct_sr")))), deadbeef->conf_get_str_fast ("streamer.samplerate", "44100"));
267-
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup_widget (w, "comboboxentry_sr_mult_48")))), deadbeef->conf_get_str_fast ("streamer.samplerate_mult_48", "48000"));
268-
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup_widget (w, "comboboxentry_sr_mult_44")))), deadbeef->conf_get_str_fast ("streamer.samplerate_mult_44", "44100"));
271+
{
272+
char samplerate[100];
273+
deadbeef->conf_get_str ("streamer.samplerate", "44100", samplerate, sizeof (samplerate));
274+
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup_widget (w, "comboboxentry_direct_sr")))), samplerate);
275+
deadbeef->conf_get_str ("streamer.samplerate_mult_48", "48000", samplerate, sizeof (samplerate));
276+
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup_widget (w, "comboboxentry_sr_mult_48")))), samplerate);
277+
deadbeef->conf_get_str ("streamer.samplerate_mult_44", "44100", samplerate, sizeof (samplerate));
278+
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup_widget (w, "comboboxentry_sr_mult_44")))), samplerate);
279+
}
269280

270281
update_samplerate_widget_sensitivity (override_sr, use_dependent_samplerate);
271282
}

0 commit comments

Comments
 (0)