Check for overflows when allocating arrays

Closes rhbz#951432.

Signed-off-by: Martin Milata <mmilata@redhat.com>