--- a/src/network/newgrf_download.cpp Tue Jul 22 23:20:33 2008 +0300
+++ b/src/network/newgrf_download.cpp Thu Jul 24 16:18:29 2008 +0300
@@ -64,13 +64,16 @@
struct check_write_ctx *ctx = (struct check_write_ctx *) arg;
// total number of bytes
- size_t len = size * nmemb;
+ size_t len = size * nmemb, oldlen = ctx->len;
+
+ // increase the size until the new data fits
+ while (ctx->offset + len + 1 > ctx->len) {
+ ctx->len *= 2;
+ }
// realloc if needed
- if (ctx->offset + len + 1 > ctx->len) {
- ctx->len *= 2;
+ if (ctx->len != oldlen)
ctx->buf = ReallocT<char>(ctx->buf, ctx->len);
- }
// thankfully we only have a limited amount of data..
memcpy(ctx->buf + ctx->offset, ptr, len);