Casts for [mc]alloc to fix compiler error with g++

This patch fixes compiler errors when compiling with g++ (>= 4.4)