Fix a segfault

Fix a segfault and make sure we give an error message instead of writing from 0x0