Fix boundary condition checking bug.
Merge pull request #39 from atgeirr/master

Fix boundary condition checking bug.
Guard against null-pointer dereference.

This restores the check that was lost in commit 79562ca.
Merge pull request #40 from bska/nullptr-deref

Guard against null-pointer dereference.