I just read lyx-devel via mail archive: Alfredo has a very valid point: Cursor positions should be valid from 0 up to _and including_ size() in a paragraph. This might require a small wrapper around a suitable STL container, but afterwards it works like a charm without any special casing whatsoever.
Just think of the cursor not being _at_ a char, but between two. So there is Char: 0 1 2 3 4 5 Pos: 0 1 2 3 4 5 6 size() == 6, valid chars pos are 0 to 5, valid cursor pos 0 to 6. Andre' [And ofcourse that's the way mathed handles it ;-}]