terminfo_spec.lua (1038B)
1 local t = require('test.unit.testutil') 2 local itp = t.gen_itp(it) 3 4 local ffi = t.ffi 5 local cimport = t.cimport 6 local to_cstr = t.to_cstr 7 local eq = t.eq 8 9 -- Import terminfo headers 10 local terminfo = cimport('./src/nvim/tui/terminfo.h') 11 12 describe('terminfo_fmt', function() 13 itp('stack overflow fails before producing output', function() 14 -- Creates a buffer 15 local buf = ffi.new('char[256]') 16 local buf_end = buf + ffi.sizeof(buf) -- One past end 17 18 -- Sets input parameters 19 local params = ffi.new('TPVAR[9]') 20 params[0].num = 65 -- 'A' 21 params[0].string = nil 22 23 -- 20 pushes (TPSTACK nums array limit) then prints one char 24 local valid_fmt = string.rep('%p1', 20) .. '%c' 25 local valid_n = terminfo.terminfo_fmt(buf, buf_end, to_cstr(valid_fmt), params) 26 eq(1, valid_n) 27 28 -- Overflows with 21 pushes and fails before print 29 local overflow_fmt = string.rep('%p1', 21) .. '%c' 30 local overflow_n = terminfo.terminfo_fmt(buf, buf_end, to_cstr(overflow_fmt), params) 31 eq(0, overflow_n) 32 end) 33 end)