CharWars Rise of the fallen strings: Replace C-String Library calls with C++ std::string Operations

Abstract

C strings are still in heavy use in C++ programs. Additionally, standardized C functions such as strcpy() and strstr() are often used to modify or analyze the content of the strings. Unfortunately, because of the fact that a C string is just a pointer to a zero-terminated character array, those functions have a lot of drawbacks regarding performance, safety and readability. The std::string class from the C++ standard library and its member functions provide a lot of the same functionality without these downsides. Building on previous work from our term project Pointerminator we extended the existing Eclipse CDT plug-in so that it helps a programmer to find and automatically refactor pieces of code, that use C strings in an unfavourable way. We started with an analysis of the various ways C strings and their related C functions are used in practice. Based on that analysis we defined possible refactorings for a subset of the standardized C string functions. We then added this functionality to the existing plug-in, wrote corresponding unit tests and documented its architecture. Finally, we tested the plug-in in the code base of an open source C++ application called XBMC. The results of these tests allowed us to optimize the plug-in and to fix some of the problems that we discovered during testing

    Similar works

    Full text

    thumbnail-image

    Available Versions