@@ -2013,16 +2013,24 @@ test(void)
keep_size = random() % 2;
break;
case OP_CLONE_RANGE:
- TRIM_OFF_LEN(offset, size, file_size);
- offset = offset & ~(block_size - 1);
- size = size & ~(block_size - 1);
- do {
- offset2 = random();
- TRIM_OFF(offset2, maxfilelen);
- offset2 = offset2 & ~(block_size - 1);
- } while (range_overlaps(offset, offset2, size) ||
- offset2 + size > maxfilelen);
- break;
+ {
+ int tries = 0;
+
+ TRIM_OFF_LEN(offset, size, file_size);
+ offset = offset & ~(block_size - 1);
+ size = size & ~(block_size - 1);
+ do {
+ if (tries++ >= 30) {
+ size = 0;
+ break;
+ }
+ offset2 = random();
+ TRIM_OFF(offset2, maxfilelen);
+ offset2 = offset2 & ~(block_size - 1);
+ } while (range_overlaps(offset, offset2, size) ||
+ offset2 + size > maxfilelen);
+ break;
+ }
case OP_DEDUPE_RANGE:
{
int tries = 0;