Fixed #5434 (FP: Out-of-bounds access with ternary operator in loop)