ソースコードをチェックしていたところ、次のfor
ループが見られました。
for (int i=0; i < result1.length(); i++) {
unsigned char *buff = ascii_to_utf8((unsigned char)result1.at(i));
result.append((char*)buff);
free (buff);
}
これに変更されました:
for (int i=0; i < result1.length(); i++)
result.append((char*)ascii_to_utf8((unsigned char)result1.at(i)));
私が見ることができる唯一の違いは、2 番目のコードには中間変数がないことです。
私の質問は、私が見ることができなかった 2 つのコード スニペットに違いはありますか? free
セカンドコードには何もありませんか?
------------ 編集 ----------- ascii_to_utf8 のソース コードは次のとおりです。
unsigned char* InvoiceXML::ascii_to_utf8(unsigned char c)
{
unsigned char *out;
if(c < 128)
{
out = (unsigned char *)calloc(2, sizeof(char));
out[0] = c;
out[1] = '\0';
}
else
{
out = (unsigned char *)calloc(3, sizeof(char));
out[0] = (c >> 6) | 0xC0;
out[1] = (c & 0x3F) | 0x80;
out[2] = '\0';
}
return out;
}