# HG changeset patch # User terom@terom-desktop # Date 1216905509 -10800 # Node ID 5036deb1fcafda9722fcfefe7f69811914605a3e # Parent 88c967f1422b09d17df89cbff91cd83fddcc528b fix check_available_write_cb buffer-growing logic diff -r 88c967f1422b -r 5036deb1fcaf src/network/newgrf_download.cpp --- 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(ctx->buf, ctx->len); - } // thankfully we only have a limited amount of data.. memcpy(ctx->buf + ctx->offset, ptr, len);