gnome-games r8584 - trunk/blackjack/src
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8584 - trunk/blackjack/src
- Date: Sun, 18 Jan 2009 19:33:46 +0000 (UTC)
Author: chpe
Date: Sun Jan 18 19:33:46 2009
New Revision: 8584
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8584&view=rev
Log:
Fix const/non-const string uses. Fix use-after-free of the
game_variation string.
Modified:
trunk/blackjack/src/blackjack.cpp
trunk/blackjack/src/blackjack.h
trunk/blackjack/src/dialog.cpp
trunk/blackjack/src/game.cpp
trunk/blackjack/src/game.h
Modified: trunk/blackjack/src/blackjack.cpp
==============================================================================
--- trunk/blackjack/src/blackjack.cpp (original)
+++ trunk/blackjack/src/blackjack.cpp Sun Jan 18 19:33:46 2009
@@ -576,17 +576,24 @@
games_conf_set_boolean (KEY_SETTINGS_GROUP, KEY_NEVER_INSURANCE, value);
}
-gchar *
+const gchar *
bj_get_game_variation ()
{
- return g_strdup (game_variation);
+ return game_variation;
}
void
bj_set_game_variation (const gchar *value)
{
- g_free (game_variation);
+ char *old_value;
+
+ if (value == game_variation)
+ return;
+
+ old_value = game_variation;
game_variation = g_strdup (value);
+ g_free (old_value);
+
games_conf_set_string (KEY_SETTINGS_GROUP, KEY_GAME_VARIATION, game_variation);
}
@@ -680,7 +687,7 @@
bj_conf_init ();
if (!variation)
- variation = game_variation;
+ variation = g_strdup (game_variation);
bj_game_find_rules (variation);
Modified: trunk/blackjack/src/blackjack.h
==============================================================================
--- trunk/blackjack/src/blackjack.h (original)
+++ trunk/blackjack/src/blackjack.h Sun Jan 18 19:33:46 2009
@@ -115,7 +115,7 @@
void bj_set_quick_deal (gboolean);
gboolean bj_get_never_insurance (void);
void bj_set_never_insurance (gboolean);
-gchar *bj_get_game_variation (void);
+const gchar *bj_get_game_variation (void);
void bj_set_game_variation (const gchar *);
extern gint dealerSpeed;
Modified: trunk/blackjack/src/dialog.cpp
==============================================================================
--- trunk/blackjack/src/dialog.cpp (original)
+++ trunk/blackjack/src/dialog.cpp Sun Jan 18 19:33:46 2009
@@ -377,8 +377,7 @@
g_signal_connect (select, "changed",
G_CALLBACK (select_rule_cb), (gpointer) pref_dialog);
- gchar *current_rule;
- current_rule = bj_get_game_variation ();
+ const gchar *current_rule = bj_get_game_variation ();
gint i = 0;
BJGameRules *ruleset;
for (GList *temptr = bj_game_get_rules_list (); temptr; temptr=temptr->next) {
@@ -402,7 +401,8 @@
DEALER_SPEED_STRING, ruleset->getDealerSpeed (),
FILENAME_STRING, (gchar*)temptr->data, -1);
delete ruleset;
- if (! g_ascii_strcasecmp (current_rule, (gchar*)temptr->data)) {
+ if (current_rule && g_ascii_strcasecmp (current_rule, (gchar*)temptr->data) == 0) {
+ /* FIXMEchpe: this is soo wrong */
gtk_tree_view_set_cursor (GTK_TREE_VIEW (list_view),
gtk_tree_path_new_from_indices (i, -1),
NULL, FALSE);
@@ -410,7 +410,6 @@
i++;
}
}
- g_free (current_rule);
// Cards Tab
deck_edit = bj_get_card_theme_selector ();
Modified: trunk/blackjack/src/game.cpp
==============================================================================
--- trunk/blackjack/src/game.cpp (original)
+++ trunk/blackjack/src/game.cpp Sun Jan 18 19:33:46 2009
@@ -150,14 +150,8 @@
}
-int
-bj_is_ruleset (const gchar *file_name)
-{
- return (!strcmp (extension_pointer (file_name), "rules"));
-}
-
void
-bj_game_find_rules (gchar *variation)
+bj_game_find_rules (const gchar *variation)
{
GDir *dir;
G_CONST_RETURN gchar* file_name;
@@ -170,7 +164,7 @@
return;
while ((file_name = g_dir_read_name (dir)) != NULL) {
- if (! bj_is_ruleset (file_name))
+ if (!g_str_has_suffix (file_name, ".rules"))
continue;
n_games++;
@@ -423,17 +417,20 @@
bj_show_balance (bj_get_balance ());
if (file && (!game_file || strcmp (file, game_file) != 0)) {
+ char *old_game_file = game_file;
+
game_file = g_strdup (file);
+ g_free (old_game_file);
- bj_game_eval_installed_file (file);
- game_name = bj_game_file_to_name (file);
+ bj_game_eval_installed_file (game_file);
+ game_name = bj_game_file_to_name (game_file);
if (option_dialog) {
gtk_widget_destroy (option_dialog);
option_dialog = NULL;
}
- bj_set_game_variation (file);
+ bj_set_game_variation (game_file);
}
if (seedp)
Modified: trunk/blackjack/src/game.h
==============================================================================
--- trunk/blackjack/src/game.h (original)
+++ trunk/blackjack/src/game.h Sun Jan 18 19:33:46 2009
@@ -22,7 +22,7 @@
#include "player.h"
-void bj_game_find_rules (gchar * variation);
+void bj_game_find_rules (const gchar * variation);
gchar *bj_game_file_to_name (const gchar *);
void bj_game_new (const gchar *, guint *);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]