More evidence that memory safety is the future for programming languages
Walter Bright
newshound2 at digitalmars.com
Thu Apr 2 20:47:10 UTC 2020
Some experimenting with clang shows it loses track of things when one level of
indirection is added:
struct S* malloc();
void free(struct S*);
void nut(struct S* s, int* pi) { free(s); *pi = 4; }
void bolt()
{
struct S* s = malloc();
struct S** ps = &s; // <= add indirection
nut(*ps, (*ps)->i);
}
or when extern functions are used (i.e. function bodies are not available).
Other things clang doesn't detect:
int* malloc();
void free(int*);
int nut();
void bolt(int i)
{
int* p = malloc();
*p = 1;
}
Doesn't find the memory leak. Also, if you write your own storage allocator,
clang doesn't pick it up.
clang actually does a nice job with what it has to work with - it's the C and
C++ languages that are not amenable to doing it 100%.
More information about the Digitalmars-d
mailing list