Use snprintf instead of sprintf if possible.

Changed to use safer versions of ```sprintf()``` if possible.