The startup Trasec is developing the TrapC programming language, which is a dialect of C that ensures safe memory operations. 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 (traps). The source code for the TrapC compiler is planned to be released in 2025.
It is claimed that the pointer handling features will not disrupt the usual workflow and will be implemented by the compiler. The language's authors intend for the compiler to ensure that pointers only refer to their associated memory areas, as well as to check all buffer boundaries. The compiler remembers types and prevents unsafe type casts. 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++ for new. There are no calls to free or delete, as memory deallocation is handled by the compiler, protecting against errors that can 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 code with pure C code in the same application, although memory safety will not be guaranteed for C code.
The project is developed by Robin Rowe, a former computer science professor who participated in the committees for the development of C and C++ standards, and who once created the graphic editor Cinepaint, which was used in the production of several Hollywood films, and the POSIX library libunistd for Windows. The co-founder of Trasec is Gabrielle Pantera, who held an executive position at Disney.
Details about the project are not yet available; only a few code examples are shown, which, for instance, state that TrapC will not let the buffer 'buff' overflow when executing 'strcpy(buff,argv[1]);' or allow the pointer or array index to increase by a value that moves it beyond the allocated buffer or the end of the array. It is not explained how such protection is achieved. // darpa_tractor.c int main(int argc,char* argv[]) { char buff[8]; // TrapC implicitly zeros, no dirty memory int success = 0; // In C, buffer overwrite corrupts success strcpy(buff,argv[1]); // TrapC cannot overrun, strcpy safe if(!strcmp(buff,"s3cr8tpw")) { success = 1; } if(success) // TrapC blocked strcpy overwrite, success good { printf("Welcome!\n"); } return !success; } // trapc_ptr.c int main() { const char* ptr = "Hello World"; // 12 char wide while(ptr) // No buffer overrun with TrapC { printf("%c",*ptr); // print one char at a time ptr++; // Steps off the end: TrapC nulls ptr! } // Do NOT attempt this in C, will segfault! assert(ptr == 0); return 0; } // trapc_array.c int score[10]; printf("%i",score[-1]); // TrapC will not allow access for(int i = 0;i
Source: opennet.ru
