refbox: validate the string size before access

The dir.size() function returns a size_type which is usually mapped to
an unsigned int. When the string is empty, the size is zero. Then subtracting
one consequently either results in undefined behavior or a wrap around.
In the latter case an invalid element is accessed.