OSDN Git Service

[Refactor] #3336 player_wipe_without_name() からmemcpy() を廃止した
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 2 Jun 2023 10:44:06 +0000 (19:44 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 3 Jun 2023 08:53:33 +0000 (17:53 +0900)
src/birth/game-play-initializer.cpp

index e4e985c..1590488 100644 (file)
 #include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
 #include "util/enum-range.h"
+#include "util/string-processor.h"
 #include "world/world.h"
+#include <algorithm>
+#include <string>
 
 /*!
  * @brief ベースアイテム構造体の鑑定済みフラグをリセットする。
@@ -45,7 +48,7 @@ static void reset_baseitem_idenditication_flags()
  */
 void player_wipe_without_name(PlayerType *player_ptr)
 {
-    auto tmp = *player_ptr;
+    const std::string backup_name = player_ptr->name;
     if (player_ptr->last_message) {
         string_free(player_ptr->last_message);
     }
@@ -163,7 +166,7 @@ void player_wipe_without_name(PlayerType *player_ptr)
         player_ptr->recall_dungeon = DUNGEON_GALGALS;
     }
 
-    memcpy(player_ptr->name, tmp.name, sizeof(tmp.name));
+    std::copy_n(backup_name.begin(), backup_name.length(), player_ptr->name);
 }
 
 /*!