ui: fix possible array overrun
cgame: little optimization
game: fix 2 possible array overruns
game: 2 little optimizations