From b4d795c13d79488a412890edd977e5128e4bf199 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Mon, 24 Nov 2025 18:41:29 +0530 Subject: [PATCH] lib: Modernize guestfs_int_drive_protocol_to_string to use static array Signed-off-by: Susant Sahani --- lib/drives.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/drives.c b/lib/drives.c index 0c31a2bd1..bb721f212 100644 --- a/lib/drives.c +++ b/lib/drives.c @@ -406,18 +406,22 @@ free_drive_struct (struct drive *drv) const char * guestfs_int_drive_protocol_to_string (enum drive_protocol protocol) { - switch (protocol) { - case drive_protocol_file: return "file"; - case drive_protocol_ftp: return "ftp"; - case drive_protocol_ftps: return "ftps"; - case drive_protocol_http: return "http"; - case drive_protocol_https: return "https"; - case drive_protocol_iscsi: return "iscsi"; - case drive_protocol_nbd: return "nbd"; - case drive_protocol_rbd: return "rbd"; - case drive_protocol_ssh: return "ssh"; - } - abort (); + static const char *const names[] = { + [drive_protocol_file] = "file", + [drive_protocol_ftp] = "ftp", + [drive_protocol_ftps] = "ftps", + [drive_protocol_http] = "http", + [drive_protocol_https] = "https", + [drive_protocol_iscsi] = "iscsi", + [drive_protocol_nbd] = "nbd", + [drive_protocol_rbd] = "rbd", + [drive_protocol_ssh] = "ssh", + }; + + if ((unsigned int)protocol < sizeof(names)/sizeof(names[0])) + return names[protocol]; + + abort(); } /**