From 46792e58dd689f6db76f35fd60b9946aba0bb846 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 16 May 2014 17:41:55 +0000 Subject: (svn r26591) -Add: some instrumentation to catch most cases where the wrong number of bytes would be written into variables during loading (or read during saving) --- src/saveload/saveload.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/saveload/saveload.h') diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 1ad885009..72c51fa69 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -212,6 +212,7 @@ struct SaveLoad { * during runtime. Decision on which one to use is controlled by the function * that is called to save it. address: global=true, offset: global=false */ void *address; ///< address of variable OR offset of variable in the struct (max offset is 65536) + size_t size; ///< the sizeof size. }; /** Same as #SaveLoad but global variables are used (for better readability); */ @@ -227,7 +228,7 @@ typedef SaveLoad SaveLoadGlobVarList; * @param to Last savegame version that has the field. * @note In general, it is better to use one of the SLE_* macros below. */ -#define SLE_GENERAL(cmd, base, variable, type, length, from, to) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable)} +#define SLE_GENERAL(cmd, base, variable, type, length, from, to) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable), cpp_sizeof(base, variable)} /** * Storage of a variable in some savegame versions. @@ -340,11 +341,11 @@ typedef SaveLoad SaveLoadGlobVarList; /** Translate values ingame to different values in the savegame and vv. */ #define SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value) -#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL} -#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL} +#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0} +#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0} /** End marker of a struct/class save or load. */ -#define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL} +#define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0} /** * Storage of global simple variables, references (pointers), and arrays. @@ -355,7 +356,7 @@ typedef SaveLoad SaveLoadGlobVarList; * @param to Last savegame version that has the field. * @note In general, it is better to use one of the SLEG_* macros below. */ -#define SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable} +#define SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable)} /** * Storage of a global variable in some savegame versions. @@ -448,7 +449,7 @@ typedef SaveLoad SaveLoadGlobVarList; #define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL} /** End marker of global variables save or load. */ -#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL} +#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL, 0} /** * Checks whether the savegame is below \a major.\a minor. -- cgit v1.2.3-54-g00ecf