This patch fixes cases where a qualifier (const, in all cases here) was
dropped by a cast, but the cast was otherwise necessary or desirable, so
the straightforward fix is to add the qualifier into the cast.
This was checked with gcc -Wcast-qual, but it doesn't fix all such
warnings, only the trivially fixable ones.