Blob Blame History Raw
From e7aa456e26e59bfa5cca1299ef2cb5299592d9da Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Wed, 5 Apr 2023 17:08:28 +0200
Subject: [PATCH] detect_kernels: tighten "try" scope

We want to catch Not_found from (our own implementation of)
"List.find_map". There's no need (and it makes no sense) to push the
"prefix_len" calculation down into the "try" scope. Keep the "try" scope
as narrow as possible.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2175703
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Vera Wu <vwu@redhat.com>
(ported from libguestfs-common commit 4003815a994944cab38d48cfc96f16382de62987)
Message-Id: <20230405150829.171720-2-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
---
 convert/linux_kernels.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/convert/linux_kernels.ml b/convert/linux_kernels.ml
index 6e9d2bdd..75ab94c4 100644
--- a/convert/linux_kernels.ml
+++ b/convert/linux_kernels.ml
@@ -122,8 +122,8 @@ let detect_kernels (g : G.guestfs) inspect family bootloader =
             *)
            let modpath, version =
              let prefix = "/lib/modules/" in
+             let prefix_len = String.length prefix in
              try
-               let prefix_len = String.length prefix in
                List.find_map (
                  fun filename ->
                    let filename_len = String.length filename in