Skip to content

Commit a678df1

Browse files
rscharfegitster
authored andcommitted
rev-parse: demonstrate overflow of N for "foo^N" and "foo~N"
If the number gets too high for an int, weird things may happen, as signed overflows are undefined. Add a test to show this; rev-parse "sucessfully" interprets 100000000000000000000000000000000 to be the same as 0, at least on x64 with GCC 9.2.1 and Clang 8.0.1, which is obviously bogus. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75b2f01 commit a678df1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

t/t1506-rev-parse-diagnosis.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,12 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
215215
test_cmp expect actual
216216
'
217217

218+
test_expect_failure 'reject Nth parent if N is too high' '
219+
test_must_fail git rev-parse HEAD^100000000000000000000000000000000
220+
'
221+
222+
test_expect_failure 'reject Nth ancestor if N is too high' '
223+
test_must_fail git rev-parse HEAD~100000000000000000000000000000000
224+
'
225+
218226
test_done

0 commit comments

Comments
 (0)