This repository was archived by the owner on Sep 30, 2024. It is now read-only.
How can checked headers add itypes to struct already defined in original system headers? #451
Labels
enhancement
New feature or request
This issue was copied from checkedc/checkedc#452
In some of our porting work, we're starting to use system functions that manipulate structs that have pointer members. For example, vsftpd calls
getpwuid
and looks at thepw_name
field of the returnedstruct passwd
, which has typechar *
. We're adding a checked declaration forgetpwuid
in #448, but in order to make the vsftpd code fully checked, we also need an itype for thepw_name
field ofstruct passwd
.The general approach in the checked headers is to include the original system headers and then redeclare things with itypes. This works fine for functions but not for structs: C does not allow a struct to be defined multiple times in the same translation unit, and Checked C does not appear to have relaxed this restriction. For example, this code:
gives the compile error:
So how can we add itypes to existing structs?
To make matters more complicated, sometimes a standard says that a struct is guaranteed to have at least certain members but might have more on some systems (example: POSIX for
struct passwd
). So it seems that what we really want here is a way to attach an itype to a given member of an existing struct in a way that will work regardless of what other members may be present. This might have to be a new Checked C language construct. One crude possible syntax would be an attribute on a redeclaration of the struct:But if you're willing to introduce dedicated syntax, that would probably be better.
An argument could have been made for filing this issue in the
checkedc-clang
repository because that's where the change probably needs to be made and in principle it could apply to third-party libraries as well as the system headers, but I decided to start here. I'm happy to file another issue incheckedc-clang
if warranted.The text was updated successfully, but these errors were encountered: