You're probably never copying the null terminator over to 'tmp'.
Remember that the null is how the computer knows it has reached the end of the string. Without it, it'll keep thinking there are more garbage characters following your string (like that mysterious 'mD')