Fix a few small issues found by coverity

A few small but real bugs found by the coverity scan that darktable does. This fixes almost everything there, except bug #35 and a few issues in the X3fDecoder that I didn't want to mess with since I don't have any working files to test it against.