Yes I am fortunate to have full control over the code. I still have some older code written by someone else to maintain, and that's pretty horrible in its architecture (incessant message passing for no good reason).
In other jobs I didn't have access to all the code but there were coding standards, regular reviews, and younger developers were mentored by older ones and their check-ins to repositories were vetted to ensure at least some standards. CPPCheck was also useful in some cases, and that Borland memory corruption tool that got built into the executable and caused false positives most of the time...
I imagine you are in the lucky position to have full control over the whole code, right?
Back on my C++ days at work, 1999 - 2005, there was always a lucky guy having to track down pointer misuses across the project source code.