src/network/newgrf_download.cpp
changeset 11185 5036deb1fcaf
parent 11181 403550141f43
equal deleted inserted replaced
11184:88c967f1422b 11185:5036deb1fcaf
    62 
    62 
    63 static size_t check_available_write_cb (void *ptr, size_t size, size_t nmemb, void *arg) {
    63 static size_t check_available_write_cb (void *ptr, size_t size, size_t nmemb, void *arg) {
    64     struct check_write_ctx *ctx = (struct check_write_ctx *) arg;
    64     struct check_write_ctx *ctx = (struct check_write_ctx *) arg;
    65     
    65     
    66     // total number of bytes
    66     // total number of bytes
    67     size_t len = size * nmemb;
    67     size_t len = size * nmemb, oldlen = ctx->len;
       
    68     
       
    69     // increase the size until the new data fits
       
    70     while (ctx->offset + len + 1 > ctx->len) {
       
    71         ctx->len *= 2;
       
    72     }
    68     
    73     
    69     // realloc if needed
    74     // realloc if needed
    70     if (ctx->offset + len + 1 > ctx->len) {
    75     if (ctx->len != oldlen)
    71         ctx->len *= 2;
       
    72         ctx->buf = ReallocT<char>(ctx->buf, ctx->len);
    76         ctx->buf = ReallocT<char>(ctx->buf, ctx->len);
    73     }
       
    74     
    77     
    75     // thankfully we only have a limited amount of data..
    78     // thankfully we only have a limited amount of data..
    76     memcpy(ctx->buf + ctx->offset, ptr, len);
    79     memcpy(ctx->buf + ctx->offset, ptr, len);
    77     ctx->offset += len;
    80     ctx->offset += len;
    78     *(ctx->buf + ctx->offset) = '\0';
    81     *(ctx->buf + ctx->offset) = '\0';