Mercurial > hg > openttd
changeset 7179:785451a03663 draft
(svn r10453) -Codechange: Allow save/load of empty (unallocated) strings
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Fri, 06 Jul 2007 08:32:00 +0000 |
parents | fbd616c593a2 |
children | b372babc875d |
files | src/saveload.cpp |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -496,6 +496,7 @@ * @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 @@ 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; }