diff options
| author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-10-29 18:27:18 +0530 |
|---|---|---|
| committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2026-10-29 18:27:18 +0530 |
| commit | 24bdc639027ac9b663fb127fba82eba232c30cab (patch) | |
| tree | b9d63891c519a756c250e1523cb9a5d7dc42c4ef | |
| parent | f7fc6ce230ee2dd3e31c6ddf2e00f9f51fe2e90e (diff) | |
Move type checks to normalize.
Let validate() check for valid values.
| -rw-r--r-- | elf/segment.lua | 11 |
1 files 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 |
