Mic*_*ael 3 c stack-overflow printf visual-studio-2010 access-violation
我正在使用visual studio 2010在C语言中编写一个程序.我使用swprintf_s函数将格式化的字符串写入wchar_t缓冲区.当我尝试写入已初始化的缓冲区时,我收到以下错误.
Unhandled exception at 0x77b3fbda in svats.exe: 0xC00000FD: Stack overflow.
Run Code Online (Sandbox Code Playgroud)
而有时
Unhandled exception at 0xfefefefe in svats.exe: 0xC0000005: Access violation.
Run Code Online (Sandbox Code Playgroud)
以下是产生访问冲突的代码.
wchar_t wBuff[1024] = L"b";
int test;
test = swprintf_s(wBuff,sizeof(wBuff),L"a%s","test");
Run Code Online (Sandbox Code Playgroud)
和堆栈溢出的代码.
wchar_t wBuff[1024] = L"b";
int test;
test = swprintf_s(wBuff,sizeof(wBuff),L"a%s",L"test");
Run Code Online (Sandbox Code Playgroud)
现在第二段代码工作了一次,不知道为什么.
谁知道问题是什么?
PS.这些文件没有加载,任何人都知道为什么?是因为visual studio是32位而我的操作系统是64位吗?
'svats.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'svats.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
Run Code Online (Sandbox Code Playgroud)
int main() {
wchar_t wBuff[1024] = L"b";
int test;
test = swprintf_s(wBuff,_countof(wBuff),L"a%s","test");
}
Run Code Online (Sandbox Code Playgroud)
这段代码会起作用.如pmg所述,第二个参数应该是1024,而不是2048.当你执行sizeof时,它将返回以字节为单位的大小.但是swprintf_s需要缓冲区中可用的字符数.您可以使用_countof哪个基本上扩展到已经建议的那个.
| 归档时间: |
|
| 查看次数: |
3261 次 |
| 最近记录: |