Code fixes

Various code fixes, mostly discovered by MSVC code static analyzer .
This is a big chunk of code.  I wonder if it might be cheaper to check for m_text NULL in the functions that use it (perhaps protect m_text behind GetText() if it's not written to?)