aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-10-27 10:26:30 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-10-27 10:26:30 +0530
commitf7fc6ce230ee2dd3e31c6ddf2e00f9f51fe2e90e (patch)
tree1498bc61d41abfddcd02c47444a6adb6f091627d
parent3cb8c81b2c9bba05fcb9ea4887acfe7a7b7fc872 (diff)
Move error checks here.
We already check for these missing fields with a nice source line highlighting in config with error(). Better than assert().
-rw-r--r--elf/header.lua14
1 files changed, 4 insertions, 10 deletions
diff --git a/elf/header.lua b/elf/header.lua
index 4ea8434..c0b8eab 100644
--- a/elf/header.lua
+++ b/elf/header.lua
@@ -26,11 +26,10 @@ local ec = require("elf.constants")
local M = {}
function M.normalize(hdr)
- assert(type(hdr) == "table", "header must be a table")
- assert(hdr.class ~= nil, "missing header field: class")
- assert(hdr.data ~= nil, "missing header field: data")
- assert(hdr.type ~= nil, "missing header field: type")
- assert(hdr.machine ~= nil, "missing header field: machine")
+ if not hdr.class then error("class is required in header", 3) end
+ if not hdr.data then error("data is required in header", 3) end
+ if not hdr.type then error("type is required in header", 3) end
+ if not hdr.machine then error("machine is required in header", 3) end
hdr.magic = hdr.magic or { 0x7f, 0x45, 0x4c, 0x46 }
hdr.ident_version = hdr.ident_version or ec.VERSION
@@ -50,11 +49,6 @@ function M.normalize(hdr)
end
function M.validate(hdr)
- if not hdr.class then error("class is required in header", 3) end
- if not hdr.data then error("data is required in header", 3) end
- if not hdr.type then error("type is required in header", 3) end
- if not hdr.machine then error("machine is required in header", 3) end
-
if hdr.class ~= ec.Class.bit32 and hdr.class ~= ec.Class.bit64 then
error("class must be Class.bit32 or Class.bit64 in header", 3)
end