Bugfix: check if values are non-NULL before copying (Thanks xeen)

fixes #1397