Skip to content

Commit d26c214

Browse files
pks-tgitster
authored andcommitted
reftable/stack: do not overwrite errors when compacting
In order to compact multiple stacks we iterate through the merged ref and log records. When there is any error either when reading the records from the old merged table or when writing the records to the new table then we break out of the respective loops. When breaking out of the loop for the ref records though the error code will be overwritten, which may cause us to inadvertently skip over bad ref records. In the worst case, this can lead to a compacted stack that is missing records. Fix the code by using `goto done` instead so that any potential error codes are properly returned to the caller. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5809004 commit d26c214

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

reftable/stack.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,16 @@ static int stack_write_compact(struct reftable_stack *st,
801801
err = 0;
802802
break;
803803
}
804-
if (err < 0) {
805-
break;
806-
}
804+
if (err < 0)
805+
goto done;
807806

808807
if (first == 0 && reftable_ref_record_is_deletion(&ref)) {
809808
continue;
810809
}
811810

812811
err = reftable_writer_add_ref(wr, &ref);
813-
if (err < 0) {
814-
break;
815-
}
812+
if (err < 0)
813+
goto done;
816814
entries++;
817815
}
818816
reftable_iterator_destroy(&it);
@@ -827,9 +825,8 @@ static int stack_write_compact(struct reftable_stack *st,
827825
err = 0;
828826
break;
829827
}
830-
if (err < 0) {
831-
break;
832-
}
828+
if (err < 0)
829+
goto done;
833830
if (first == 0 && reftable_log_record_is_deletion(&log)) {
834831
continue;
835832
}
@@ -845,9 +842,8 @@ static int stack_write_compact(struct reftable_stack *st,
845842
}
846843

847844
err = reftable_writer_add_log(wr, &log);
848-
if (err < 0) {
849-
break;
850-
}
845+
if (err < 0)
846+
goto done;
851847
entries++;
852848
}
853849

0 commit comments

Comments
 (0)