uart: fix issue where a index is checked before set