@@ -493,12 +493,13 @@ static void SlSaveLoadConv(void *ptr, Va
* @param ptr pointer to the stringbuffer
* @param length maximum length of the string (buffer). If -1 we don't care
* about a maximum length, but take string length as it is.
* @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);
}
/** Calculate the gross length of the string that it
* will occupy in the savegame. This includes the real length, returned
* by SlCalcNetStringLen and the length that the index will occupy.
@@ -570,15 +571,19 @@ static void SlString(void *ptr, size_t l
SlCopyBytes(ptr, len);
break;
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;
if (len == 0) {
*(char**)ptr = NULL;
} else {
((char*)ptr)[len] = '\0'; // properly terminate the string