gpt4 book ai didi

c++ - vswprintf 崩溃

转载 作者:行者123 更新时间:2023-11-28 04:01:29 26 4
gpt4 key购买 nike

使用 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 手册页一百次之后)我能弄清楚为什么这段代码在 vswprintf 调用长字符串时崩溃了 :-( 完全相同的代码有效在 Linux 机器上很好。为 str 分配了足够的内存,而且 vswprintf 正在检查缓冲区是否溢出。不幸的是,... S60 调试器在这次崩溃时没有中断,所以我没有详细信息:-(

有人有什么想法吗?

假设 Symbian 的 vswprintf 例程中存在错误,使用 POSIX 兼容代码的可能替换函数是什么? (这应该是一个跨平台的库)

谢谢。

最佳答案

对我来说,这看起来像是进入 vswprintf() 调用的工作。即使您只能进行汇编级调试,也应该通过监视 str[] 内存中发生的事情,或多或少地清楚发生了什么。

关于c++ - vswprintf 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/213875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com