GCC 4.9 warning fixes

Some warning fixes, there are still many to go.
The build still does not succeed with -O2, just with -O0