Saw this in the translated "SaferCPlusPlus" output examples. static void string_set(char** out, const char* in)
What happened there? Where are the array types? Wrong place to look?If inference can't make a definitely good decision, maybe translators should guess, conservatively. That is, if it looks like something needs an array type parameter, make it an array type parameter with subscript checking. Then run tests on the translated program and see if that works. That's what humans do on such code. Machine learning has potential here. For any array in a working program, there must be some expression of some variables that expresses the size of the array. If humans can't find that expression, the program is unmaintainable and probably has a bug. There are really 3 cases. 1. this is a pointer, and it's never subscripted or offset. That's a pointer to a single instance of something. 2. this is a pointer which is subscripted or offset, and we can tell from context how big the array is. 3. This is a pointer which is subscripted or offset, but auto-translation fails to figure out how big the array is supposed to be. The problem is to convert (3) into (2). I tend to think that a good metric for C code quality is how hard that is. If it's not obvious by looking how big something is supposed to be, there's probably a potential bug. [1] https://github.com/duneroadrunner/SaferCPlusPlus-AutoTransla... |
I think you should find that array buffers of other types, like "unsigned char" or "const unsigned char", and their associated pointer iterators are translated to their corresponding macros. I'd be interested if you find otherwise. If you're interested, the relevant code for the translator is in the "safercpp" subdirectory [2]. It's not super-well commented so if you have any questions feel free to post them in the "issues" section of the repository.
[1] https://github.com/duneroadrunner/SaferCPlusPlus-AutoTransla...
[2] https://github.com/duneroadrunner/SaferCPlusPlus-AutoTransla...