From 397d582031d0105aaa18bf1d5afb40b27515f506 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 14 May 2023 18:41:36 +0000 Subject: [PATCH] Use NSDMI for zero-initialized Mission members Prefer non-static data member initializers over leaving the member undefined in the constructor and relying on the caller to zero the member afterward. --- common/main/mission.h | 23 +++++------------------ similar/main/mission.cpp | 13 ------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/common/main/mission.h b/common/main/mission.h index 8e4840a86..e02b376de 100644 --- a/common/main/mission.h +++ b/common/main/mission.h @@ -152,30 +152,17 @@ struct Mission : Mission_path std::unique_ptr secret_level_names; int builtin_hogsize; // the size of the hogfile for a builtin mission, and 0 for an add-on mission ntstring mission_name; - d_fname briefing_text_filename; // name of briefing file - d_fname ending_text_filename; // name of ending file + d_fname briefing_text_filename{}; // name of briefing file + d_fname ending_text_filename{}; // name of ending file anarchy_only_level anarchy_only_flag; // if true, mission is only for anarchy - ubyte last_level; - sbyte last_secret_level; - ubyte n_secret_levels; + uint8_t last_level{}; + int8_t last_secret_level{}; + uint8_t n_secret_levels{}; #if defined(DXX_BUILD_DESCENT_II) descent_version_type descent_version; // descent 1 or descent 2? std::unique_ptr alternate_ham_file; std::unique_ptr extra_robot_movie; #endif - /* Explicitly default move constructor and move operator= - * - * Without this, gcc (tested gcc-4.9, gcc-5) tries to use - * a synthetic operator=(const Mission &) to implement `instance = - * {};`, which fails because Mission contains std::unique_ptr, a - * movable but noncopyable type. - * - * With the explicit default, gcc uses operator=(Mission &&), which - * works. - * - * Explicitly delete copy constructor and copy operator= for - * thoroughness. - */ Mission(Mission &&) = default; Mission &operator=(Mission &&) = default; Mission(const Mission &) = delete; diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index b5df69a73..b5607a2e9 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -914,19 +914,6 @@ static const char *load_mission(const mle *const mission) Current_mission->descent_version = mission->descent_version; #endif Current_mission->anarchy_only_flag = mission->anarchy_only_flag; - Current_mission->n_secret_levels = 0; -#if defined(DXX_BUILD_DESCENT_II) - Current_mission->alternate_ham_file = NULL; -#endif - - //init vars - Current_mission->last_level = 0; - Current_mission->last_secret_level = 0; - Current_mission->briefing_text_filename = {}; - Current_mission->ending_text_filename = {}; - Current_mission->secret_level_table.reset(); - Current_mission->level_names.reset(); - Current_mission->secret_level_names.reset(); // for Descent 1 missions, load descent.hog #if defined(DXX_BUILD_DESCENT_II)