fix undefined behavior in fmt_trim()