The memory allocation in vec might panic in the case of capacity overflow. Move the allocation outside the function to fix the test.