def expand(values, index, padding=128):
    """ Modify in place and return the list values[] by appending
        zeros to ensure that values[index] is not out of bounds.
        An error is raised if index is negative.
    """
    assert index >= 0, f"Oops: negative index in expand(values, index={index})"
    if index >= len(values):
        space_needed = index - len(values) + 1
        values.extend([0] * (space_needed + padding))
    return values