IsValidRef

Helper function to test whether the buffer is valid.