fix potential crash

Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
possibly really fix the crash on macosx

Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
get rid of dubious cast

Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>