R_RSA_PUBLIC_KEY publickey;
strncpy((char *)&publickey, (char *)PointToKey,
sizeof(R_RSA_PUBLIC_KEY));
以上 string copy 時會有問題
R_RSA_PUBLIC_KEY 是一個 structure
unsigned char *PointToKey;
我想把一個 structure 的 date 都 copy 到 PointToKey 這個 pointer
所指的位址,結果資料 copy 有問題,並非我想要的。
我就改成下面的樣子
void strncpy_my(char *st1, char *st2, int n)
{
int i;
for (i=0;i<n;i++)
*(st1+i) = *(st2+i);
}
R_RSA_PUBLIC_KEY publickey;
strncpy_my((char *)&publickey, (char *)PointToKey,
sizeof(R_RSA_PUBLIC_KEY));
自己寫一個 strncpy_my 結果就沒問題了,是什麼原因呢???
char *strncpy(char *dest, const char *src, size_t maxlen);
^^^^^^^^^^^^^^^
你 src, dest 的位置搞錯了吧!
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>