From 24bdc639027ac9b663fb127fba82eba232c30cab Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Thu, 29 Oct 2026 18:27:18 +0530 Subject: Move type checks to normalize. Let validate() check for valid values. --- elf/segment.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/elf/segment.lua b/elf/segment.lua index 50fb011..6b3c635 100644 --- a/elf/segment.lua +++ b/elf/segment.lua @@ -16,12 +16,10 @@ local fmt = require("elf.fmt") ---@class Segments local M = {} - function M.normalize(phdrs) - assert(type(phdrs) == "table", "segments must be a table") - for i, phdr in ipairs(phdrs) do - assert(type(phdr) == "table", ("segment %d must be a table"):format(i)) - assert(phdr.type ~= nil, ("missing segment %d field: type"):format(i)) + for _, phdr in ipairs(phdrs) do + if type(phdr) ~= "table" then error("segment must be table", 3) end + if not phdr.type then error("type is required in segment", 3) end phdr.flags = phdr.flags or 0 phdr.offset = phdr.offset or 0 @@ -35,8 +33,7 @@ end function M.validate(phdrs) for _, phdr in ipairs(phdrs) do - if not phdr.type then error("type is required in segment", 3) end - -- TODO additional validations + -- TODO validations end end -- cgit v1.3