OSDN Git Service

[Fix] #39962 read_dead_file() にsize_t 引数を追加 / Added size_t argument to read_dead_file()
authorHourier <hourier@users.sourceforge.jp>
Mon, 24 Feb 2020 06:48:37 +0000 (15:48 +0900)
committerHourier <hourier@users.sourceforge.jp>
Mon, 24 Feb 2020 06:48:37 +0000 (15:48 +0900)
src/files.c
src/files.h
src/view/process-death.c
src/view/process-death.h

index 55bbdd4..9584316 100644 (file)
@@ -74,6 +74,7 @@ concptr ANGBAND_DIR_BONE; //!< Bone files for player ghosts (ascii) These files
 concptr ANGBAND_DIR_DATA; //!< Binary image files for the "*_info" arrays (binary) These files are not portable between platforms
 concptr ANGBAND_DIR_EDIT; //!< Textual template files for the "*_info" arrays (ascii) These files are portable between platforms
 concptr ANGBAND_DIR_SCRIPT; //!< Script files These files are portable between platforms.
+concptr ANGBAND_DIR_FILE; //!< Various extra files (ascii) These files may be portable between platforms
 concptr ANGBAND_DIR_HELP; //!< Help files (normal) for the online help (ascii) These files are portable between platforms
 concptr ANGBAND_DIR_INFO; //!< Help files (spoilers) for the online help (ascii) These files are portable between platforms
 concptr ANGBAND_DIR_PREF; //!< Default user "preference" files (ascii) These files are rarely portable between platforms
@@ -4950,18 +4951,19 @@ errr counts_write(player_type *creature_ptr, int where, u32b count)
 /*!
  * @brief 墓のアスキーアートテンプレを読み込む
  * @param buf テンプレへのバッファ
+ * @param buf_size バッファの長さ
  * @return なし
  */
-void read_dead_file(char *buf)
+void read_dead_file(char *buf, size_t buf_size)
 {
-       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("dead_j.txt", "dead.txt"));
+       path_build(buf, buf_size, ANGBAND_DIR_FILE, _("dead_j.txt", "dead.txt"));
 
        FILE *fp;
        fp = my_fopen(buf, "r");
        if (!fp) return;
 
        int i = 0;
-       while (my_fgets(fp, buf, sizeof(buf)) == 0)
+       while (my_fgets(fp, buf, buf_size) == 0)
        {
                put_str(buf, i++, 0);
        }
index ce55f14..7f550a6 100644 (file)
@@ -37,7 +37,7 @@ extern void do_cmd_save_game(player_type *creature_ptr, int is_autosave);
 extern void do_cmd_save_and_exit(player_type *player_ptr);
 extern void exit_game_panic(player_type *creature_ptr);
 extern errr get_rnd_line(concptr file_name, int entry, char *output);
-void read_dead_file(char* buf);
+void read_dead_file(char* buf, size_t buf_size);
 
 #ifdef JP
 extern errr get_rnd_line_jonly(concptr file_name, int entry, char *output, int count);
index 7315e5c..92e7989 100644 (file)
@@ -16,8 +16,6 @@
 
 #define GRAVE_LINE_WIDTH 31
 
-concptr ANGBAND_DIR_FILE; //!< Various extra files (ascii) These files may be portable between platforms
-
 /*!
  * @brief 墓石の真ん中に文字列を書き込む /
  * Centers a string within a GRAVE_LINE_WIDTH character string         -JWT-
@@ -38,10 +36,9 @@ static void center_string(char *buf, concptr str)
  * @param buf 墓テンプレへのバッファ
  * @return 追加の行数
  */
-static int show_killing_monster(player_type *dead_ptr, char *buf)
+static int show_killing_monster(player_type *dead_ptr, char *buf, char *tmp)
 {
-       char tmp[160];
-       roff_to_buf(dead_ptr->died_from, GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
+       roff_to_buf(dead_ptr->died_from, GRAVE_LINE_WIDTH + 1, tmp, sizeof(tmp));
        char *t;
        t = tmp + strlen(tmp) + 1;
        if (!*t) return 0;
@@ -88,12 +85,11 @@ static int show_killing_monster(player_type *dead_ptr, char *buf)
  * @param creature_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-void print_tomb(player_type *dead_ptr, void(*read_dead_file)(char*))
+void print_tomb(player_type *dead_ptr, void(*read_dead_file)(char*, size_t))
 {
        Term_clear();
        char buf[1024];
-       (*read_dead_file)(buf);
-
+       (*read_dead_file)(buf, sizeof(buf));
        concptr p = (current_world_ptr->total_winner || (dead_ptr->lev > PY_MAX_LEVEL))
                ? _("偉大なる者", "Magnificant")
                : player_title[dead_ptr->pclass][(dead_ptr->lev - 1) / 5];
@@ -143,7 +139,7 @@ void print_tomb(player_type *dead_ptr, void(*read_dead_file)(char*))
        }
        else
        {
-               extra_line = show_killing_monster(dead_ptr, buf);
+               extra_line = show_killing_monster(dead_ptr, buf, tmp);
        }
 
        center_string(buf, tmp);
index 2421842..2e1b24c 100644 (file)
@@ -2,5 +2,5 @@
 
 #include "angband.h"
 
-void print_tomb(player_type *dead_ptr, void(*read_dead_file)(char*));
+void print_tomb(player_type *dead_ptr, void(*read_dead_file)(char*, size_t));
 void show_info(player_type *creature_ptr, void(*handle_stuff)(player_type*), errr(*file_character)(player_type*, concptr), void(*update_playtime)(void), void(*displayer_player)(player_type*, int));