C fixes

Some fixes to random C modules, to get a build with fewer warnings and fix some undefined behaviors.