From 84fad4e00ab09971781bb38d685e98c3a4d8449d Mon Sep 17 00:00:00 2001 From: BenjiReis Date: Mon, 9 Oct 2023 14:34:04 +0200 Subject: [PATCH] Do not fetch random SR in empty list When looking for a random SR in an empty list, quicktest can call `Random.int 0` which will throw. Instead return an empty list. Instead of throwing, the test won't be passed as there is no compatible SR. This can happen when calling quickest with the `-sr` on ISO SR. Signed-off-by: BenjiReis --- ocaml/quicktest/qt_filter.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ocaml/quicktest/qt_filter.ml b/ocaml/quicktest/qt_filter.ml index 7d5a11e9aad..57fad7ef98e 100644 --- a/ocaml/quicktest/qt_filter.ml +++ b/ocaml/quicktest/qt_filter.ml @@ -198,8 +198,11 @@ module SR = struct let random srs () = let srs = srs () in - let index = Random.int @@ List.length srs in - [List.nth srs index] + if srs = [] then + [] + else + let index = Random.int @@ List.length srs in + [List.nth srs index] let sr_filter f srs () = List.filter f (srs ())