summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-01-17 06:44:47 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-01-17 06:44:47 +0000
commite086d5eefd17d2977bd4b84aaf9f9631ae154700 (patch)
tree13a00c20476f0fa21bfa168a612732bddc427f6a /crawl-ref/source
parentb8b9746bd48eaad7b7489948b640cb6c650ec81c (diff)
downloadcrawl-ref-e086d5eefd17d2977bd4b84aaf9f9631ae154700.tar.gz
crawl-ref-e086d5eefd17d2977bd4b84aaf9f9631ae154700.zip
Fixed id array being clobbered if Crawl receives SIGHUP with the player in a
shop. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@858 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/externs.h6
-rw-r--r--crawl-ref/source/itemname.cc20
-rw-r--r--crawl-ref/source/itemname.h2
-rw-r--r--crawl-ref/source/shopping.cc27
-rw-r--r--crawl-ref/source/shopping.h3
-rw-r--r--crawl-ref/source/tags.cc4
6 files changed, 43 insertions, 19 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index c5a3009723..688152562b 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -688,11 +688,12 @@ struct game_state
bool need_save; // Set to true when game has started.
bool saving_game; // Set to true while in save_game.
bool updating_scores; // Set to true while updating hiscores.
+ bool shopping; // Set if id has been munged for shopping.
int seen_hups; // Set to true if SIGHUP received.
game_state() : need_save(false), saving_game(false),
- updating_scores(false), seen_hups(0)
+ updating_scores(false), shopping(false), seen_hups(0)
{
}
};
@@ -1111,4 +1112,7 @@ extern const char* god_gain_power_messages[MAX_NUM_GODS][MAX_GOD_ABILITIES];
typedef int keycode_type;
+typedef FixedArray < int, 4, 50 > id_fix_arr;
+typedef char id_arr[4][50];
+
#endif // EXTERNS_H
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index cd07ab2eb4..75f07f40a7 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -38,7 +38,11 @@
#include "view.h"
#include "items.h"
-char id[NUM_IDTYPE][MAX_SUBTYPES];
+id_arr id;
+
+// Backup of the id array used to save ids if the game receives SIGHUP
+// when the character is in a shop.
+id_arr shop_backup_id;
static bool is_random_name_space( char let );
static bool is_random_name_vowel( char let);
@@ -1903,17 +1907,11 @@ static const char *item_name_2(
return (buff);
} // end item_name_2()
-void save_id(char identy[4][50])
+void save_id(id_arr identy, bool saving_game)
{
- int x = 0, jx = 0;
-
- for (x = 0; x < 4; x++)
- {
- for (jx = 0; jx < 50; jx++)
- {
- identy[x][jx] = id[x][jx];
- }
- }
+ memcpy(identy,
+ (!saving_game || !crawl_state.shopping)? id : shop_backup_id,
+ sizeof id);
} // end save_id()
void clear_ids(void)
diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h
index 4401a72172..a264c6fbe4 100644
--- a/crawl-ref/source/itemname.h
+++ b/crawl-ref/source/itemname.h
@@ -99,7 +99,7 @@ int make_name( unsigned long seed, bool all_caps, char buff[ ITEMNAME_SIZE ] );
/* ***********************************************************************
* called from: files - shopping
* *********************************************************************** */
-void save_id(char identy[4][50]);
+void save_id(id_arr identy, bool saving_game = false);
/* ***********************************************************************
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index d69444caee..8f41ed4fce 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -1612,6 +1612,27 @@ unsigned int item_value( item_def item, id_arr id, bool ident )
return (valued);
} // end item_value()
+// Protect the id array against being clobbered by a SIGHUP with the
+// character in a shop.
+extern id_arr shop_backup_id;
+class shopping_hup_protect
+{
+public:
+ shopping_hup_protect() : shopping(crawl_state.shopping)
+ {
+ save_id(shop_backup_id);
+ crawl_state.shopping = true;
+ }
+
+ ~shopping_hup_protect()
+ {
+ crawl_state.shopping = shopping;
+ }
+
+private:
+ bool shopping;
+};
+
void shop(void)
{
unsigned char i = 0;
@@ -1632,7 +1653,11 @@ void shop(void)
save_id(identy);
- in_a_shop(i, identy);
+ {
+ shopping_hup_protect shp;
+ in_a_shop(i, identy);
+ }
+
you.redraw_gold = 1;
burden_change();
diff --git a/crawl-ref/source/shopping.h b/crawl-ref/source/shopping.h
index 0de4edb2bd..fd33af98f5 100644
--- a/crawl-ref/source/shopping.h
+++ b/crawl-ref/source/shopping.h
@@ -16,9 +16,6 @@
#include "externs.h"
-typedef FixedArray < int, 4, 50 > id_fix_arr;
-typedef char id_arr[4][50];
-
void shop_init_id_type(int shoptype, id_fix_arr &shop_id);
void shop_uninit_id_type(int shoptype, const id_fix_arr &shop_id);
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index e2d1f13b55..88982c10af 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -837,9 +837,9 @@ static void tag_construct_you_items(struct tagHeader &th)
// this is really dumb. We copy the id[] array from itemname
// to the stack, for no good reason that I can see.
- char identy[4][50];
+ id_arr identy;
- save_id(identy);
+ save_id(identy, true);
for (i = 0; i < 4; ++i)
{