back-port changes to sub_find_name2 from v3.0.x
Be more careful in name2_cmp