Only call offset() after checking vals.length

Fixes issue #4930