From 2c4184a675c44c2b279a9a28b135be4da96493af Mon Sep 17 00:00:00 2001 From: Peter Rugg Date: Fri, 7 Jun 2024 15:42:32 +0100 Subject: [PATCH] Avoid type-unsafe use of 'head' Since the value had come out of split, and the inputs are sanitised by argparse, this wasn't an acutal issue, but it was generating some CI warnings. --- src/RISCV/ArchDesc.hs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/RISCV/ArchDesc.hs b/src/RISCV/ArchDesc.hs index bd540ad..81bde33 100644 --- a/src/RISCV/ArchDesc.hs +++ b/src/RISCV/ArchDesc.hs @@ -150,17 +150,19 @@ fromString str = ArchDesc { has_xlen_32 = True } where rawSplit = splitOneOf "_zx" (map toLower str) archStrings = filter (\x -> not $ null x) rawSplit - rv64 = (head archStrings) =~ "rv64" - i = (head archStrings =~ "i") || (head archStrings =~ "g") - m = (head archStrings =~ "m") || (head archStrings =~ "g") - s = (head archStrings =~ "s") || (head archStrings =~ "g") - a = (head archStrings =~ "a") || (head archStrings =~ "g") - f = (head archStrings =~ "f") || (head archStrings =~ "g") - d = (head archStrings =~ "d") || (head archStrings =~ "g") - icsr = elem "icsr" archStrings || (head archStrings =~ "g") - ihpm = elem "ihpm" archStrings || (head archStrings =~ "g") - ifencei = elem "ifencei" archStrings || (head archStrings =~ "g") - c = head archStrings =~ "c" - n = head archStrings =~ "n" + archHead = case archStrings of [] -> "" + h:t -> h + rv64 = (archHead) =~ "rv64" + i = (archHead =~ "i") || (archHead =~ "g") + m = (archHead =~ "m") || (archHead =~ "g") + s = (archHead =~ "s") || (archHead =~ "g") + a = (archHead =~ "a") || (archHead =~ "g") + f = (archHead =~ "f") || (archHead =~ "g") + d = (archHead =~ "d") || (archHead =~ "g") + icsr = elem "icsr" archStrings || (archHead =~ "g") + ihpm = elem "ihpm" archStrings || (archHead =~ "g") + ifencei = elem "ifencei" archStrings || (archHead =~ "g") + c = archHead =~ "c" + n = archHead =~ "n" cheri = elem "cheri" archStrings nocloadtags = elem "nocloadtags" archStrings