When you pop bar because bar is shorter:
Bar can't extend right past index (bar is shorter).
Bar can't extend left past the new stack top (that bar was shorter than ).
Between those boundaries, all bars are at least as tall as (they were pushed after and before being popped). So the width calculation is correct.