While moving higher or equal priority operations to expression stack in
yagl_glsl_state_pp_condition_parse_add_op function the state->pp_ops
array could be accessed with index -1. Reorder the while() expression
to avoid an out of array bounds access. This fixes an issue indicated
with SVACE warning:
* OVERFLOW_UNDER_CHECK: Buffer 'state->pp_ops' of size 64 accessed at
yagl_glsl_state.c:640 can overflow, since its index 'state->pp_current_op
- 1' can have value -1 that is out of range, as indicated by preceding
conditional expression at yagl_glsl_state.c:640.
[overflow] overflow at emulator-yagl-1.6/GLESv2/yagl_glsl_state.c:640
[check: Sub] Sub at emulator-yagl-1.6/GLESv2/yagl_glsl_state.c:640
[declaration] Shift at emulator-yagl-1.6/GLESv2/yagl_glsl_state.c:640
Change-Id: I2cb6a16ce6c3302f8a2dd4fe92bd8bfbec11c5ca
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
}
// move higher or equal priority operations to expression stack
- while (glsl_pp_op_prio[op] <= glsl_pp_op_prio[state->pp_ops[state->pp_current_op - 1]] &&
- state->pp_current_op > 0) {
+ while (state->pp_current_op > 0 &&
+ glsl_pp_op_prio[op] <= glsl_pp_op_prio[state->pp_ops[state->pp_current_op - 1]]) {
assert(state->pp_current_expr < YAGL_GLSL_PP_EXPRESSION_STACK_SIZE);
state->pp_current_op--;
state->pp_exprs[state->pp_current_expr].op = state->pp_ops[state->pp_current_op];