robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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