Nov 2021
Here we describe using the scpptool tool to assist in the conversion of native C code to SaferCPlusPlus (a memory-safe subset of C++).
To demonstrate how to use it, this repository contains an example of the conversion tool being applied to an open source png encoder/decoder written in C.
Note that, by default, the conversion tool doesn't necessarily produce (performance) optimal SaferCPlusPlus code. Instead it uses SaferCPlusPlus elements that map directly to the (unsafe) native elements they are replacing. In fact, if you add the -ConvertMode Dual
command line option, rather than being replaced with corresponding SaferCPlusPlus elements directly, the unsafe native elements are replaced with macros that allow you to use a compile-time directive to "disable" the SaferCPlusPlus elements and "restore" the original (unsafe) implementation. That is, adding -DMSE_LEGACYHELPERS_DISABLED
to the compile options of the converted code, should make it essentially equivalent to the original (unsafe) code, generating the same, or nearly the same, machine code as the (unconverted) original code.
Also, while far from complete in general, the auto-conversion feature currently has quite limited support for converting elements that are generated by preprocessor macros. For example, it'll likely struggle with converting elements generated by nested macros, or macro-generated arguments to macro functions. This seems to be a common issue with many larger legacy C code bases.