Should not be possible for it to ever happen that rest is 0 here, but should really say

if (rest && (0 == rb[rest-1]))