File diff r25601:747c128b2f85 → r25602:6ef361b0a726
src/saveload/saveload.cpp
Show inline comments
 
@@ -581,13 +581,13 @@ static inline uint SlGetArrayLength(size
 
/**
 
 * Return the size in bytes of a certain type of normal/atomic variable
 
 * as it appears in memory. See VarTypes
 
 * @param conv VarType type of variable that is used for calculating the size
 
 * @return Return the size of this type in bytes
 
 */
 
uint SlCalcConvMemLen(VarType conv)
 
static inline uint SlCalcConvMemLen(VarType conv)
 
{
 
	static const byte conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
 
	byte length = GB(conv, 4, 4);
 

	
 
	switch (length << 4) {
 
		case SLE_VAR_STRB:
 
@@ -940,12 +940,15 @@ static void SlString(void *ptr, size_t l
 
		case SLA_LOAD_CHECK:
 
		case SLA_LOAD: {
 
			size_t len = SlReadArrayLength();
 

	
 
			switch (GetVarMemType(conv)) {
 
				default: NOT_REACHED();
 
				case SLE_VAR_NULL:
 
					SlSkipBytes(len);
 
					return;
 
				case SLE_VAR_STRB:
 
					if (len >= length) {
 
						DEBUG(sl, 1, "String length in savegame is bigger than buffer, truncating");
 
						SlCopyBytes(ptr, length);
 
						SlSkipBytes(len - length);
 
						len = length - 1;
 
@@ -1004,14 +1007,18 @@ static void SlStdString(void *ptr, VarTy
 
			break;
 
		}
 

	
 
		case SLA_LOAD_CHECK:
 
		case SLA_LOAD: {
 
			size_t len = SlReadArrayLength();
 
			if (GetVarMemType(conv) == SLE_VAR_NULL) {
 
				SlSkipBytes(len);
 
				return;
 
			}
 

	
 
			char *buf = AllocaM(char, len + 1);
 

	
 
			SlCopyBytes(buf, len);
 
			buf[len] = '\0'; // properly terminate the string
 

	
 
			StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK;
 
			if ((conv & SLF_ALLOW_CONTROL) != 0) {
 
				settings = settings | SVS_ALLOW_CONTROL_CODE;
 
@@ -1466,12 +1473,14 @@ size_t SlCalcObjMemberLength(const void 
 
 * Check whether the variable size of the variable in the saveload configuration
 
 * matches with the actual variable size.
 
 * @param sld The saveload configuration to test.
 
 */
 
[[maybe_unused]] static bool IsVariableSizeRight(const SaveLoad &sld)
 
{
 
	if (GetVarMemType(sld.conv) == SLE_VAR_NULL) return true;
 

	
 
	switch (sld.cmd) {
 
		case SL_VAR:
 
			switch (GetVarMemType(sld.conv)) {
 
				case SLE_VAR_BL:
 
					return sld.size == sizeof(bool);
 
				case SLE_VAR_I8: