fix bugs about string operations ; `snprintf' will check the length of string