sprintfでsrcとdstが同じ場合って未定義ですか?
sprintf(buf, "%s%d", buf, a);とか
sprintf(buf, "%d%s", a, buf);みたいな場合。
後者だと内容破壊されそうですけども