Ticket refs #7333: fix warnings, code analysis and clean up the code
- Fix all errors catched by cppcheck threadsafety (cppcheck --error-exitcode=0 --addon=threadsafety bbf)
- Fix some errors catched by cppcheck cert (cppcheck --error-exitcode=0 --addon=cert bbf)
- Add new str-protected macros instead of using str functions directly to avoid crashes