A startup called Trasec is developing the TrapC programming language, which is a dialect of C designed for safe memory handling. To prevent memory-related errors, such as buffer overflows and accessing already freed memory, TrapC uses a fundamentally different approach to pointers and a special error-handling mechanism based on exception handlers (trap). The source code for the TrapC compiler is planned to be open-sourced in 2025.
It is stated that the pointer handling features will not disrupt the usual workflow and will be implemented by the compiler. According to the language's authors, the compiler will guarantee that pointers only refer to their associated memory areas and will check all buffer boundaries. The compiler tracks types and prevents unsafe type casting. All created variables and buffers are explicitly initialized or filled with zeros by the compiler.
Instead of malloc, TrapC uses a constructor similar to C++ called new. Calls to free and delete are absent, and memory management is the compiler's responsibility, protecting against errors that lead to memory leaks. Incremental automatic memory management is used in the heap, but without a garbage collector. At the ABI level, TrapC will be compatible with C, allowing the combination of TrapC and pure C code in a single application, though memory safety won't be guaranteed for C code.
The project is led by Robin Rowe, a former computer science professor who participated in committees for the development of C and C++ standards, and who created the Cinepaint graphics editor, used in the production of some Hollywood films, as well as the POSIX library libunistd for Windows. The co-founder of Trasec is Gabrielle Pantera, who held a leadership position at Disney.
Os detalhes do projeto ainda não foram divulgados, apenas alguns exemplos de código são mostrados, onde, por exemplo, é afirmado que o TrapC não permitirá o estouro do buffer buff ao executar "strcpy(buff,argv[1]);" ou não permitirá que o ponteiro ou índice do array se desloque para um valor que o coloque além da memória alocada ou do final do array. Não é explicado como essa proteção é alcançada. \/\/ darpa_tractor.c int main(int argc,char* argv[]) { char buff[8]; \/\/ TrapC zera implicitamente, nenhuma memória suja int success = 0;\/\/ Em C, a sobrescrita do buffer corrompe success strcpy(buff,argv[1]); \/\/ TrapC não pode ultrapassar, strcpy seguro if(!strcmp(buff,"s3cr8tpw")) { success = 1; } if(success) \/\/ TrapC bloqueou a sobrescrita de strcpy, sucesso bom { printf("Bem-vindo!\n"); } return !success; } \/\/ trapc_ptr.c int main() { const char* ptr = "Hello World"; \/\/ 12 caracteres while(ptr) \/\/ Sem estouro de buffer com TrapC { printf("%c",*ptr); \/\/ imprime um caractere de cada vez ptr++; \/\/ Passa do final: TrapC zera ptr! } \/\/ Não tente isso em C, causará falha! assert(ptr == 0); return 0; } \/\/ trapc_array.c int score[10]; printf("%i",score[-1]); \/\/ TrapC não permitirá acesso for(int i = 0;i
Fonte: opennet.ru
