-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
This issue was copied from checkedc/checkedc-clang#410
The following program type checks in checked mode, and yet it will core dump because it permits changing a bounds expression via a pointer. This seems like a serious problem, since it's at the heart of what the type system will/will not support.
#include <stdlib_checked.h>
#include <stdio_checked.h>
#pragma BOUNDS_CHECKED ON
struct p {
_Array_ptr<char> buf : count(len);
unsigned int len;
};
void foo(_Ptr<struct p> ptr) {
unsigned int i;
for (int i=0; i<ptr->len; i++) {
ptr->buf[i] = 'a';
_Unchecked { printf("Assigning index %d an %c\n",i,'a'); }
ptr->len++;
}
}
int main(int argc, _Nt_array_ptr<char> argv[] : count(argc)) {
_Ptr<struct p> p = 0;
p = malloc(sizeof(struct p));
p->buf = malloc(10);
p->len = 10;
foo(p);
return 0;
}