Check that the value is not nil before deferencing it

This fixes #274.

There's no tests yet, as I can't find how to run the test suite correctly. I had a look around the tests, I believe `TestMarshalNil` is a good candidate to test this.

I ran my example test case from #274 against this fix and everything works correctly.
If I manage to run the test suite, I'll add some tests.