bzflag
bzflag copied to clipboard
Replace char arrays with std::string
As a reminder...
One of my low-priority todo items is to replace character arrays with std::string to help ensure that there are no overflows we have overlooked.
- BulletCatcher
I took a look through the code, 99% of the use of char arrays is using them as byte buffers for things like images, or fixed size data structures like those used in network transport. These aren't really "string" operations they are just using byte buffers.
There are only place I can see that could be changed to use std::string since they are doing text processing is in curses_wraper.h.
inline int pd_waddstr(WINDOW* w, const char* str) { return waddstr(w, std::string(str).c_str()); }
maybe you could also do the temp buffer for the downloaded world, but I'm not sure that's going to save you anything much since it's treated like a byte buffer (for compression and stuff).
There just doesn't seem to be much C style text manipulation going on where buffer overruns could happen.
One of the bugs in our current implementation of pd_waddstr()
is that we don't check for new
failure, which would cause a segfault. The above rewrite would fix that bug, is easier to read, and only needs a brief comment explaining why pd_waddstr()
exists to exemplify maintainable code.
I have found no buffer overflows in our code, but each use of a character array for a string carries a significant risk that a future change will inadvertently create an overflow situation. Replacing them with std::string
will reduce the likelihood of new overflow bugs.
Also, if there are few places where this makes sense then this will be an easy task. 😃 This issue is meant to be an enticing opportunity for a new contributor.