This patch enables extended diagnostics. Additionally, it fixes issues found by compilers and static analyzers to make it work.