thermal: fix potential out-of-bounds memory access