Fix off by one error when allocating array