10 月 2 日にリリースされた Symbian S60 第 5 版 SDK を使用して、次のコード スニペットをコンパイル/実行しています (sim 上で):
void test(wchar_t *dest, int size, const wchar_t *fmt, ...) {
va_list vl;
va_start(vl, fmt);
vswprintf(dest, size, fmt, vl);
va_end(vl);
}
...
wchar_t str[1024];
// this crashes (2nd string 123 characters (+ \0) equals 248 bytes)
test(str, 1024, L"msg: %S", L"this is a test messagethis is a test messagethis is a test messagethis is a test messagethis is a test messagethis is a tes");
// this works (2nd string 122 characters (+ \0) equals 246 bytes)
test(str, 1024, L"msg: %S", L"this is a test messagethis is a test messagethis is a test messagethis is a test messagethis is a test messagethis is a te");
明らかな理由はありませんが ( vswprintfのマニュアル ページを 100 回読んだ後でも)、長い文字列の vswprintf 呼び出しでこのコードがクラッシュする理由を理解できます :-(まったく同じコードが Linux ボックスで正常に動作します. str には十分なメモリが割り当てられており、さらに vswprintf はとにかくバッファ オーバーランをチェックしています. 残念ながら ... S60 デバッガはこのクラッシュで壊れないので、詳細はわかりません :-(
誰にもアイデアはありますか?
Symbian の vswprintf ルーチンにバグがあると仮定すると、POSIX 準拠のコードを使用した代替関数として何が考えられるでしょうか? (これはクロスプラットフォームのライブラリであるはずです)
ありがとう。