Changeset - r25524:02dac61ae3ed
[Not reviewed]
master
0 2 0
rubidium42 - 3 years ago 2021-05-26 19:48:28
rubidium@openttd.org
Change: mark copy-assignment as deleted for classes with a copy-constructor that is not trivial

This to prevent the default copy-assignment getting used when during the assignment also some other memory needs to be allocated as that would otherwise be freed.
2 files changed with 9 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/error.h
Show inline comments
 
@@ -23,43 +23,46 @@ enum WarningLevel {
 
	WL_WARNING,  ///< Other information
 
	WL_ERROR,    ///< Errors (eg. saving/loading failed)
 
	WL_CRITICAL, ///< Critical errors, the MessageBox is shown in all cases
 
};
 

	
 
/** The data of the error message. */
 
class ErrorMessageData {
 
protected:
 
	GUITimer display_timer;         ///< Timer before closing the message.
 
	uint64 decode_params[20];       ///< Parameters of the message strings.
 
	const char *strings[20];        ///< Copies of raw strings that were used.
 
	const GRFFile *textref_stack_grffile; ///< NewGRF that filled the #TextRefStack for the error message.
 
	uint textref_stack_size;        ///< Number of uint32 values to put on the #TextRefStack for the error message.
 
	uint32 textref_stack[16];       ///< Values to put on the #TextRefStack for the error message.
 
	StringID summary_msg;           ///< General error message showed in first line. Must be valid.
 
	StringID detailed_msg;          ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID.
 
	Point position;                 ///< Position of the error message window.
 
	CompanyID face;                 ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present.
 

	
 
public:
 
	ErrorMessageData(const ErrorMessageData &data);
 
	~ErrorMessageData();
 
	ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
 

	
 
	/* Remove the copy assignment, as the default implementation will not do the right thing. */
 
	ErrorMessageData &operator=(ErrorMessageData &rhs) = delete;
 

	
 
	/** Check whether error window shall display a company manager face */
 
	bool HasFace() const { return face != INVALID_COMPANY; }
 

	
 
	void SetDParam(uint n, uint64 v);
 
	void SetDParamStr(uint n, const char *str);
 

	
 
	void CopyOutDParams();
 
};
 

	
 
void ScheduleErrorMessage(const ErrorMessageData &data);
 

	
 
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
 
bool HideActiveErrorMessage();
 

	
 
void ClearErrorMessages();
 
void ShowFirstError();
 
void UnshowCriticalError();
 

	
 
#endif /* ERROR_H */
src/newgrf_config.h
Show inline comments
 
@@ -92,89 +92,95 @@ struct GRFIdentifier {
 
		MemCpyT(this->md5sum, md5sum, lengthof(this->md5sum));
 
	}
 

	
 
	GRFIdentifier& operator =(const GRFIdentifier &other) = default;
 

	
 
	/**
 
	 * Does the identification match the provided values?
 
	 * @param grfid  Expected grfid.
 
	 * @param md5sum Expected md5sum, may be \c nullptr (in which case, do not check it).
 
	 * @return the object has the provided grfid and md5sum.
 
	 */
 
	inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
 
	{
 
		if (this->grfid != grfid) return false;
 
		if (md5sum == nullptr) return true;
 
		return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
 
	}
 
};
 

	
 
/** Information about why GRF had problems during initialisation */
 
struct GRFError {
 
	GRFError(StringID severity, StringID message = 0);
 
	GRFError(const GRFError &error);
 

	
 
	/* Remove the copy assignment, as the default implementation will not do the right thing. */
 
	GRFError &operator=(GRFError &rhs) = delete;
 

	
 
	std::string custom_message; ///< Custom message (if present)
 
	std::string data;           ///< Additional data for message and custom_message
 
	StringID message;           ///< Default message
 
	StringID severity;          ///< Info / Warning / Error / Fatal
 
	uint32 param_value[2];      ///< Values of GRF parameters to show for message and custom_message
 
};
 

	
 
/** The possible types of a newgrf parameter. */
 
enum GRFParameterType {
 
	PTYPE_UINT_ENUM, ///< The parameter allows a range of numbers, each of which can have a special name
 
	PTYPE_BOOL,      ///< The parameter is either 0 or 1
 
	PTYPE_END,       ///< Invalid parameter type
 
};
 

	
 
/** Information about one grf parameter. */
 
struct GRFParameterInfo {
 
	GRFParameterInfo(uint nr);
 
	GRFParameterInfo(GRFParameterInfo &info);
 
	GRFTextList name;      ///< The name of this parameter
 
	GRFTextList desc;      ///< The description of this parameter
 
	GRFParameterType type; ///< The type of this parameter
 
	uint32 min_value;      ///< The minimal value this parameter can have
 
	uint32 max_value;      ///< The maximal value of this parameter
 
	uint32 def_value;      ///< Default value of this parameter
 
	byte param_nr;         ///< GRF parameter to store content in
 
	byte first_bit;        ///< First bit to use in the GRF parameter
 
	byte num_bit;          ///< Number of bits to use for this parameter
 
	SmallMap<uint32, GRFTextList> value_names; ///< Names for each value.
 
	bool complete_labels;  ///< True if all values have a label.
 

	
 
	uint32 GetValue(struct GRFConfig *config) const;
 
	void SetValue(struct GRFConfig *config, uint32 value);
 
	void Finalize();
 
};
 

	
 
/** Information about GRF, used in the game and (part of it) in savegames */
 
struct GRFConfig : ZeroedMemoryAllocator {
 
	GRFConfig(const char *filename = nullptr);
 
	GRFConfig(const GRFConfig &config);
 
	~GRFConfig();
 

	
 
	/* Remove the copy assignment, as the default implementation will not do the right thing. */
 
	GRFConfig &operator=(GRFConfig &rhs) = delete;
 

	
 
	GRFIdentifier ident;                        ///< grfid and md5sum to uniquely identify newgrfs
 
	uint8 original_md5sum[16];                  ///< MD5 checksum of original file if only a 'compatible' file was loaded
 
	char *filename;                             ///< Filename - either with or without full path
 
	GRFTextWrapper name;                        ///< NOSAVE: GRF name (Action 0x08)
 
	GRFTextWrapper info;                        ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
 
	GRFTextWrapper url;                         ///< NOSAVE: URL belonging to this GRF.
 
	GRFError *error;                            ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B)
 

	
 
	uint32 version;                             ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown
 
	uint32 min_loadable_version;                ///< NOSAVE: Minimum compatible version a NewGRF can define
 
	uint8 flags;                                ///< NOSAVE: GCF_Flags, bitset
 
	GRFStatus status;                           ///< NOSAVE: GRFStatus, enum
 
	uint32 grf_bugs;                            ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
 
	uint32 param[0x80];                         ///< GRF parameters
 
	uint8 num_params;                           ///< Number of used parameters
 
	uint8 num_valid_params;                     ///< NOSAVE: Number of valid parameters (action 0x14)
 
	uint8 palette;                              ///< GRFPalette, bitset
 
	std::vector<GRFParameterInfo *> param_info; ///< NOSAVE: extra information about the parameters
 
	bool has_param_defaults;                    ///< NOSAVE: did this newgrf specify any defaults for it's parameters
 

	
 
	struct GRFConfig *next;                     ///< NOSAVE: Next item in the linked list
 

	
 
	void CopyParams(const GRFConfig &src);
 

	
0 comments (0 inline, 0 general)