Fix build warnings

Hi,

Mostly cosmetic changes to make gcc happy.
Still have a lot of "discards 'const' qualifier from pointer target type"

At  least c616a1b seems a real bug.