-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expand global table size #811
Conversation
need to remember to check and update this with each release
is there a regression test we could add that will fail the build if it's wrong? |
Probably could be done with a lua script at runtime: just start at |
I'll see if I can write a test like that |
testing this: -- validates that the size in df.globals.xml is correct
function test.global_table_size()
local elem_size = df.global_table_entry:sizeof()
local declared_arr_size = df.global.global_table:sizeof() // elem_size
for i=0,declared_arr_size-2 do
expect.true_(df._displace(df.global.global_table[0], i, elem_size).address,
'nil address found in middle of global_table')
end
expect.false_(df._displace(df.global.global_table[0], declared_arr_size-1, elem_size).address,
'nil *not* found at end of declared global-table')
end |
version 2 of the test: -- validates that the size in df.globals.xml is correct
function test.global_table_size()
local elem_size = df.global_table_entry:sizeof()
local declared_arr_size = df.global.global_table:sizeof() // elem_size
for i=0,declared_arr_size-1 do
expect.true_(df._displace(df.global.global_table[0], i, elem_size).address,
'nil address found in middle of global_table at idx ' .. i)
end
if df._displace(df.global.global_table[0], declared_arr_size, elem_size).address then
local idx_of_nil
for i=declared_arr_size+1,declared_arr_size*2 do
if not df._displace(df.global.global_table[0], i, elem_size).address then
idx_of_nil = i
break
end
end
expect.fail('nil *not* found at end of declared global-table (idx ' .. declared_arr_size .. '); table size should be: ' .. idx_of_nil)
end
end output: Check failed! nil *not* found at end of declared global-table (idx 366); table size should be: 379
at ...eamapps/common/Dwarf Fortress/hack/scripts/test/core.lua:58
test failed: core:global_table_size |
you know just how to push my buttons |
I will point out that attempting to read past the actual last element is UB, and so it's probably safer to scan the table until you find the terminator. This will identify its actual length. Then compare with what is declared; if different, fail. If the declared length is greater than the actual length, reading that element will read unspecified memory. |
good point. will fix |
ok, the test correctly fails in https://github.com/DFHack/dfhack/actions/runs/12076775793 |
need to remember to check and update this with each release