Revision 35d7ace7 block/qcow2-snapshot.c

b/block/qcow2-snapshot.c
317 317
{
318 318
    BDRVQcowState *s = bs->opaque;
319 319
    QCowSnapshot *sn;
320
    int i, snapshot_index, l1_size2;
320
    int i, snapshot_index;
321
    int cur_l1_bytes, sn_l1_bytes;
321 322

  
322 323
    snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
323 324
    if (snapshot_index < 0)
......
330 331
    if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0)
331 332
        goto fail;
332 333

  
333
    s->l1_size = sn->l1_size;
334
    l1_size2 = s->l1_size * sizeof(uint64_t);
334
    cur_l1_bytes = s->l1_size * sizeof(uint64_t);
335
    sn_l1_bytes = sn->l1_size * sizeof(uint64_t);
336

  
337
    if (cur_l1_bytes > sn_l1_bytes) {
338
        memset(s->l1_table + sn->l1_size, 0, cur_l1_bytes - sn_l1_bytes);
339
    }
340

  
335 341
    /* copy the snapshot l1 table to the current l1 table */
336 342
    if (bdrv_pread(bs->file, sn->l1_table_offset,
337
                   s->l1_table, l1_size2) != l1_size2)
343
                   s->l1_table, sn_l1_bytes) < 0)
338 344
        goto fail;
339 345
    if (bdrv_pwrite_sync(bs->file, s->l1_table_offset,
340
                    s->l1_table, l1_size2) < 0)
346
                    s->l1_table, cur_l1_bytes) < 0)
341 347
        goto fail;
342 348
    for(i = 0;i < s->l1_size; i++) {
343 349
        be64_to_cpus(&s->l1_table[i]);

Also available in: Unified diff