A couple of years ago, I made a simple oversight that resulted in a bizarre problem unrelated to any change I made. I have always followed a careful practice of frequent version updates and once I spotted the very stupid mistake I made, I was thankful because otherwise I don't know that I would have been able to spot the mistake since it was totally unrelated to the perceived issue.
I have since paid close attention to changes in DarkPlaces, ezQuake and sometime others to their string handling methods.
snprintf
I've entirely replaced sprintf and vsprintf with snprintf and vsnprintf (yes I know about the dp versions) modelled after Fruitz of Dojo (the Mac Quake port).
Old: sprintf(filestring,"%s/*", host_parms.basedir);
New: snprintf(filestring, sizeof(filestring),"%s/*", host_parms.basedir);
This was rather easy to globally replace using a POSIX Search/Replace in TextPad5 -- and important to me to NOT do it manually -- a single typo on my part could have the same effect as what I seek to fix.

POSIX replace
Code: Select all
Find: sprintf (\([]&[.a-zA-Z0-9_]+\),
Replace With: snprintf(\1, sizeof(\1),strcpy
I hate strcpy. It disturbs me.
I plan to replace it as such:
Old: strcpy (scr_centerstring, str);
New: strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
The description of strncpy is "No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length of the C string in source is less than num."
So this looks safe to me.
strcat
DarkPlaces uses strlcat ... but I haven't quite walked through it in my head and haven't figured out how I can "robotically" (search and replace) replace it yet.