robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
47388614cb
master
1// Coverity Scan model 2// 3// This is a modeling file for Coverity Scan. Modeling helps to avoid false 4// positives. 5// 6// - A model file can't import any header files. 7// - Therefore only some built-in primitives like int, char and void are 8// available but not wchar_t, NULL etc. 9// - Modeling doesn't need full structs and typedefs. Rudimentary structs 10// and similar types are sufficient. 11// - An uninitialized local pointer is not an error. It signifies that the 12// variable could be either NULL or have some data. 13// 14// Coverity Scan doesn't pick up modifications automatically. The model file 15// must be uploaded by an admin in the analysis settings of 16// http://scan.coverity.com/projects/neovim-neovim 17// 18 19// Issue 105985 20// 21// Teach coverity that uv_pipe_open saves fd on success (0 return value) 22// and doesn't save it on failure (return value != 0). 23 24struct uv_pipe_s { 25int something ; 26}; 27 28int uv_pipe_open (struct uv_pipe_s * handle ,int fd ) 29{ 30int result ; 31if (result == 0 ) { 32__coverity_escape__ (fd ); 33 } 34return result ; 35} 36 37// Hint Coverity that adding item to d avoids losing track 38// of the memory allocated for item. 39typedef struct {}dictitem_T ; 40typedef struct {}dict_T ; 41int tv_dict_add (dict_T * const d ,dictitem_T * const item ) 42{ 43__coverity_escape__ (item ); 44} 45 46void * malloc (size_t size ) 47{ 48int has_mem ; 49if (has_mem ) 50return __coverity_alloc__ (size ); 51else 52return 0 ; 53} 54 55void * try_malloc (size_t size ) 56{ 57size_t allocated_size = size ?size :1 ; 58return malloc (allocated_size ); 59} 60 61void * xmalloc (size_t size ) 62{ 63void * p = malloc (size ); 64if (!p ) 65__coverity_panic__ (); 66return p ; 67} 68 69void xfree (void * ptr ) 70{ 71__coverity_free__ (ptr ); 72} 73 74void * xcalloc (size_t count ,size_t size ) 75{ 76size_t allocated_count = count && size ?count :1 ; 77size_t allocated_size = count && size ?size :1 ; 78void * p = try_malloc (allocated_count * allocated_size ); 79if (!p ) 80__coverity_panic__ (); 81__coverity_writeall0__ (p ); 82return p ; 83} 84 85void * xrealloc (void * ptr ,size_t size ) 86{ 87__coverity_escape__ (ptr ); 88void * p = xmalloc (size ); 89__coverity_writeall__ (p ); 90return p ; 91} 92 93void * xmallocz (size_t size ) 94{ 95void * p = malloc (size + 1 ); 96 ((char * )p )[size ]= 0 ; 97return p ; 98} 99 100void * xmemdupz (const void * data ,size_t len ) 101{ 102void * p = xmallocz (len ); 103__coverity_writeall__ (p ); 104 ((char * )p )[len ]= 0 ; 105return p ; 106} 107 108void * xmemdup (const void * data ,size_t len ) 109{ 110void * p = xmalloc (len ); 111__coverity_writeall__ (p ); 112return p ; 113} 114 115// Teach coverity that lua errors are noreturn 116 117typedef struct {}lua_State ; 118 119int luaL_typerror (lua_State * L ,int narg ,const char * tname ) 120{ 121__coverity_panic__ (); 122return 0 ; 123} 124 125int luaL_error (lua_State * L ,const char * fmt , ...) 126{ 127__coverity_panic__ (); 128return 0 ; 129} 130 131int luaL_argerror (lua_State * L ,int numarg ,const char * extramsg ) 132{ 133__coverity_panic__ (); 134return 0 ; 135} 136 137void * luaL_checkudata (lua_State * L ,int ud ,const char * tname ) 138{ 139return __coverity_alloc_nosize__ () 140} 141