The case we're talking about was search after arrest.
If immunity [to a warrantless search] is to be conceived of as a rule, there is one exception that has been established as firmly as the rule itself. The government may search the person of the accused when legally arrested to discover and seize the fruit or evidences of crime.
also (cited in Harris v US):
The right without a search warrant contemporaneously to search persons lawfully arrested while committing crime and to search the place where the arrest is made in order to find and seize things connected with the crime as its fruits or as the means by which it was committed, as well as weapons and other things of effect an escape from custody is not to be doubted.
Officer safety is one of three motivations for search incident to arrest I've read about; two more are evidence collection (as above), and mitigating the risk that evidence that could later be collected via warrant might be destroyed.
Terry stops, on the other hand, are motivated solely by officer safety.