robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
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 () 14itp ( 'stack overflow fails before producing output' , function () 15-- Creates a buffer 16local buf =ffi . new ( 'char[256]' ) 17local buf_end =buf + ffi . sizeof ( buf ) -- One past end 18 19-- Sets input parameters 20local params =ffi . new ( 'TPVAR[9]' ) 21params [ 0 ]. num =65 -- 'A' 22params [ 0 ]. string =nil 23 24-- 20 pushes (TPSTACK nums array limit) then prints one char 25local valid_fmt =string . rep ( '%p1' , 20 ) .. '%c' 26local valid_n =terminfo . terminfo_fmt ( buf , buf_end , to_cstr ( valid_fmt ), params ) 27eq ( 1 , valid_n ) 28 29-- Overflows with 21 pushes and fails before print 30local overflow_fmt =string . rep ( '%p1' , 21 ) .. '%c' 31local overflow_n =terminfo . terminfo_fmt ( buf , buf_end , to_cstr ( overflow_fmt ), params ) 32eq ( 0 , overflow_n ) 33end ) 34end )