Thanks to @codemeow I fixed some bugs and warnings found with cppcheck. NOTE: it seems like all static analyzer fail to detect the assert macro or hate combining assert ans if checks.