因为你没有
空值
在内存中字符串末尾的章程。分配内存时,必须考虑这种情况。然后,有两种方法可以解决您的问题:
1)
createpass = xcalloc(len+1, sizeof(char));
memset(createpass, 0, len+1);
</code>
要么
2)
createpass = xcalloc(len+1, sizeof(char));
memset(createpass, 0, len+1); // option, because the ‘sprintf’ will fill a ‘\0’ at the end of string automatically.
sprintf(createpass, “%s%s”, userpass, salt);
</code>
INJOY。