summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-07-06 08:32:00 +0000
committerpeter1138 <peter1138@openttd.org>2007-07-06 08:32:00 +0000
commita8b385d77d877c37be8e789d9ae8d72584dfdfa8 (patch)
tree98c9a3546ca31fa020597b5d978baabc6f752752 /src
parent1af0fc0a33e60ff8d72852aaadc7bff4bd321a38 (diff)
downloadopenttd-a8b385d77d877c37be8e789d9ae8d72584dfdfa8.tar.xz
(svn r10453) -Codechange: Allow save/load of empty (unallocated) strings
Diffstat (limited to 'src')
-rw-r--r--src/saveload.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/saveload.cpp b/src/saveload.cpp
index dd70f7a4a..86e515200 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -496,6 +496,7 @@ static void SlSaveLoadConv(void *ptr, VarType conv)
* @return return the net length of the string */
static inline size_t SlCalcNetStringLen(const char *ptr, size_t length)
{
+ if (ptr == NULL) return 0;
return minu(strlen(ptr), length - 1);
}
@@ -573,9 +574,13 @@ static void SlString(void *ptr, size_t length, VarType conv)
case SLE_VAR_STR:
case SLE_VAR_STRQ: // Malloc'd string, free previous incarnation, and allocate
free(*(char**)ptr);
- *(char**)ptr = (char*)malloc(len + 1); // terminating '\0'
- ptr = *(char**)ptr;
- SlCopyBytes(ptr, len);
+ if (len == 0) {
+ *(char**)ptr = NULL;
+ } else {
+ *(char**)ptr = (char*)malloc(len + 1); // terminating '\0'
+ ptr = *(char**)ptr;
+ SlCopyBytes(ptr, len);
+ }
break;
}