Change unsafe functions to safe functions

Fix issue #6430.