util.c: fix possible out of bounds array access