correctcomputation / checkedc-clang

This is the primary development repository for 3C, a tool for automatically converting legacy C code to the Checked C extension of C, which aims to enforce spatial memory safety. This repository is a fork of Checked C's.
14 stars 5 forks source link

Conflicting rewrites for extern sized arrays #733

Open kyleheadley opened 2 years ago

kyleheadley commented 2 years ago

This happens in Lua:

lapi.c:35:12: error: redefinition of 'lua_ident' with a different type: 'const char _Checked[]' vs '_Array_ptr<const char>'
const char lua_ident _Checked[] =
           ^
./lua.h:147:31: note: previous declaration is here
extern _Array_ptr<const char> lua_ident : count(129);
                              ^

and in ZLib:

../trees.h:73:11: error (redefinition): redefinition of '_dist_code' with a different type: 'const uch _Checked[512]' vs '_Array_ptr<const uch>' (aka '_Array_ptr<const unsigned char>')
const uch _dist_code _Checked[DIST_CODE_LEN] = {
          ^
../deflate.h:321:32: note: previous declaration is here
  extern _Array_ptr<const uch> _dist_code : count(512);
                               ^

The compiler does not complain for simple examples, like when 3C converts one line in each file.

kyleheadley commented 2 years ago

also in libtiff(macro-expanded -alltypes):

libtiff/tif_fax3sm.c:5:22: error: redefinition of 'TIFFFaxMainTable' with a different type: 'const TIFFFaxTabEnt _Checked[128]' vs '_Array_ptr<const TIFFFaxTabEnt>'
 const TIFFFaxTabEnt TIFFFaxMainTable _Checked[128] = {
                     ^
libtiff/tif_fax3.h:90:40: note: previous declaration is here
extern _Array_ptr<const TIFFFaxTabEnt> TIFFFaxMainTable : count(128);
                                       ^
john-h-kastner commented 2 years ago

Here's a simple test case:

extern const char lua_ident[];
const char lua_ident[] = "foo";

converts to

extern _Array_ptr<const char> lua_ident : count(4);
const char lua_ident _Checked[] = "foo";

Note that the error does not occur if the definition comes before the declaration.