Fix integer overflows while intializing reference lists

Instead of looping through all poc/pic numbers with an increment
of 1, loop through only valid poc/pic numbers after sorting them.
This prevents integer overflows when poc/pic number is INT32_MIN or
INT32_MAX

This also fixes a timeout issue seen when integer sanitizers are
not enabled

Bug: 135303936
Bug: 136568141
Bug: 141276890
Test: poc in bug

Change-Id: I5db80dd8e811cbb1a9ecd00363fac997551ccaf5
2 files changed