summaryrefslogtreecommitdiff
path: root/src/saveload/saveload.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-27 21:51:06 +0000
committerrubidium <rubidium@openttd.org>2009-01-27 21:51:06 +0000
commit7d64441008be46cbdf36df938ba8183407fed258 (patch)
treebdc1cf77911ecc0a2bd07b94e5bc0a91fc77841a /src/saveload/saveload.cpp
parent7dbd0582b6c1aa22a0345d63a2b71b98013c84d2 (diff)
downloadopenttd-7d64441008be46cbdf36df938ba8183407fed258.tar.xz
(svn r15287) -Cleanup: some code style, remove erroneous comment.
-Document: the fact that zlib reads uninitialised data (valgrind notices this) and that it won't be fixed in zlib and that we can't do anything about it except ignoring it.
Diffstat (limited to 'src/saveload/saveload.cpp')
-rw-r--r--src/saveload/saveload.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 58cc791c5..0f241f3a1 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1101,7 +1101,7 @@ static size_t ReadLZO()
if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Bad checksum");
/* Decompress */
- lzo1x_decompress(out + sizeof(uint32)*1, size, _sl.buf, &len, NULL);
+ lzo1x_decompress(out + sizeof(uint32) * 1, size, _sl.buf, &len, NULL);
return len;
}
@@ -1110,13 +1110,13 @@ static size_t ReadLZO()
static void WriteLZO(size_t size)
{
byte out[LZO_SIZE + LZO_SIZE / 64 + 16 + 3 + 8];
- byte wrkmem[sizeof(byte*)*4096];
+ byte wrkmem[sizeof(byte*) * 4096];
uint outlen;
- lzo1x_1_compress(_sl.buf, (lzo_uint)size, out + sizeof(uint32)*2, &outlen, wrkmem);
+ lzo1x_1_compress(_sl.buf, (lzo_uint)size, out + sizeof(uint32) * 2, &outlen, wrkmem);
((uint32*)out)[1] = TO_BE32(outlen);
((uint32*)out)[0] = TO_BE32(lzo_adler32(0, out + sizeof(uint32), outlen + sizeof(uint32)));
- if (fwrite(out, outlen + sizeof(uint32)*2, 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
+ if (fwrite(out, outlen + sizeof(uint32) * 2, 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
}
static bool InitLZO()
@@ -1255,7 +1255,7 @@ static bool InitWriteZlib()
if (deflateInit(&_z, 6) != Z_OK) return false;
_sl.bufsize = 4096;
- _sl.buf = _sl.buf_ori = MallocT<byte>(4096); // also contains fread buffer
+ _sl.buf = _sl.buf_ori = MallocT<byte>(4096);
return true;
}
@@ -1269,8 +1269,17 @@ static void WriteZlibLoop(z_streamp z, byte *p, size_t len, int mode)
do {
z->next_out = buf;
z->avail_out = sizeof(buf);
+
+ /**
+ * For the poor next soul who sees many valgrind warnings of the
+ * "Conditional jump or move depends on uninitialised value(s)" kind:
+ * According to the author of zlib it is not a bug and it won't be fixed.
+ * http://groups.google.com/group/comp.compression/browse_thread/thread/b154b8def8c2a3ef/cdf9b8729ce17ee2
+ * [Mark Adler, Feb 24 2004, 'zlib-1.2.1 valgrind warnings' in the newgroup comp.compression]
+ **/
r = deflate(z, mode);
- /* bytes were emitted? */
+
+ /* bytes were emitted? */
if ((n = sizeof(buf) - z->avail_out) != 0) {
if (fwrite(buf, n, 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
}