Skip to content

Commit c03a46b

Browse files
committed
Fixed tiny little bug that would cause our own chunk to be overridden before we make one last computation with its unaltered values
1 parent 6656c66 commit c03a46b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

_delta_apply.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ uint DCV_copy_slice_to(const DeltaChunkVector* src, DeltaChunk* dest, ull ofs, u
456456
DC_offset_copy_to(cdc, dest, relofs, cdc->ts - relofs < size ? cdc->ts - relofs : size);
457457
cdc += 1;
458458
size -= dest->ts;
459-
dest += 1;
459+
dest += 1; // must be here, we are reading the size !
460460
num_chunks += 1;
461461

462462
if (size == 0){
@@ -472,7 +472,7 @@ uint DCV_copy_slice_to(const DeltaChunkVector* src, DeltaChunk* dest, ull ofs, u
472472
DC_copy_to(cdc, dest++);
473473
size -= cdc->ts;
474474
} else {
475-
DC_offset_copy_to(cdc, dest++, 0, size);
475+
DC_offset_copy_to(cdc, dest, 0, size);
476476
size = 0;
477477
break;
478478
}
@@ -526,7 +526,6 @@ bool DCV_connect_with_base(DeltaChunkVector* tdcv, const DeltaChunkVector* bdcv)
526526
return 0;
527527
}
528528

529-
fprintf(stderr, "old size = %i\n", (int)tdcv->size);
530529
uint* pofs = offset_array;
531530
uint num_addchunks = 0;
532531

@@ -574,17 +573,19 @@ bool DCV_connect_with_base(DeltaChunkVector* tdcv, const DeltaChunkVector* bdcv)
574573
}
575574

576575
// Copy Chunks, and move their target offset into place
576+
// As we could override dc when slicing, we get the data here
577+
const ull relofs = dc->to - dc->so;
578+
577579
DeltaChunk* tdc = dc + ofs;
578580
DeltaChunk* tdcend = tdc + DCV_copy_slice_to(bdcv, tdc, dc->so, dc->ts);
579-
const ull relofs = dc->to - dc->so;
580581
for(;tdc < tdcend; tdc++){
581582
tdc->to += relofs;
582583
}
583584
}
584585

585-
fprintf(stderr, "NEW size = %i\n", (int)tdcv->size);
586586
DBG_check(tdcv);
587587
assert(DCV_size(tdcv) == oldsize);
588+
588589
PyMem_Free(offset_array);
589590
return 1;
590591
}

0 commit comments

Comments
 (0)