我在 VS2012 上的 Windows 8.1 x64 上遇到 GetFileAttributedA 的特殊问题。这些函数运行良好,但偶尔该语句会崩溃并显示
MyService.exe 中 0x00000003 处未处理的异常:0xC0000005:执行位置 0x00000003 时发生访问冲突。
这是伪代码。
char szItemAbsPath[MAX_PATH];
DWORD rc = 0;
DWORD dwFileAttribute = 0;
memset(szItemAbsPath, '\0', sizeof(szItemAbsPath));
sprintf(szItemAbsPath, "%s%s%s", "D:\\Root", FILE_SEPARATOR_STR, "temp.txt");
// check item type
dwFileAttribute = GetFileAttributesA(szItemAbsPath); //this is where program crashes
if (dwFileAttribute == INVALID_FILE_ATTRIBUTES)
{
rc = GetLastError();
return rc;
}
if (dwFileAttribute & FILE_ATTRIBUTE_DIRECTORY)
{
// this is a dir
}
我基本上想检查给定的项目是否是文件或文件夹。有时在 32 位版本中也会出现此问题。
迷你转储
Dump Summary
------------
Dump File: MyDesktopService.dmp : C:\Users\anand\Desktop\MyDesktopService.dmp
Last Write Time: 09-04-2014 17:34:24
Process Name: MyDesktopService.exe : D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MyDesktopService.exe
Process Architecture: x86
Exception Code: 0xC0000005
Exception Information: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
Heap Information: Present
System Information
------------------
OS Version: 6.2.9200
CLR Version(s):
Modules
-------
Module Name Module Path Module Version
----------- ----------- --------------
MyDesktopService.exe D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MyDesktopService.exe 0.0.0.0
ntdll.dll C:\Windows\System32\ntdll.dll 6.3.9600.16502
kernel32.dll C:\Windows\System32\kernel32.dll 6.3.9600.16520
KERNELBASE.dll C:\Windows\System32\KERNELBASE.dll 6.3.9600.16496
MSVCR110D.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MSVCR110D.dll 11.0.51106.1
MyDesktop.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\MyDesktop.dll 0.0.0.0
libeay32.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\libeay32.dll 1.0.1.6
wtsapi32.dll C:\Windows\System32\wtsapi32.dll 6.3.9600.16384
userenv.dll C:\Windows\System32\userenv.dll 6.3.9600.16384
advapi32.dll C:\Windows\System32\advapi32.dll 6.3.9600.16384
ws2_32.dll C:\Windows\System32\ws2_32.dll 6.3.9600.16384
libcurl_debug.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\libcurl_debug.dll 7.34.0.0
jansson.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\jansson.dll 0.0.0.0
gdi32.dll C:\Windows\System32\gdi32.dll 6.3.9600.16421
user32.dll C:\Windows\System32\user32.dll 6.3.9600.16441
msvcr110.dll C:\Windows\System32\msvcr110.dll 11.0.51106.1
msvcrt.dll C:\Windows\System32\msvcrt.dll 7.0.9600.16384
rpcrt4.dll C:\Windows\System32\rpcrt4.dll 6.3.9600.16384
profapi.dll C:\Windows\System32\profapi.dll 6.3.9600.16384
sechost.dll C:\Windows\System32\sechost.dll 6.3.9600.16384
nsi.dll C:\Windows\System32\nsi.dll 6.3.9600.16384
Wldap32.dll C:\Windows\System32\Wldap32.dll 6.3.9600.16384
normaliz.dll C:\Windows\System32\normaliz.dll 6.3.9600.16384
ssleay32.dll D:\Works\My\My_Recovered_from_SVN_Crash\MyVS2012\NSLib\ssleay32.dll 1.0.1.6
sspicli.dll C:\Windows\System32\sspicli.dll 6.3.9600.16408
CRYPTBASE.dll C:\Windows\System32\CRYPTBASE.dll 6.3.9600.16384
bcryptPrimitives.dll C:\Windows\System32\bcryptPrimitives.dll 6.3.9600.16384
winsta.dll C:\Windows\System32\winsta.dll 6.3.9600.16384
IPHLPAPI.DLL C:\Windows\System32\IPHLPAPI.DLL 6.3.9600.16384
winnsi.dll C:\Windows\System32\winnsi.dll 6.3.9600.16384
dhcpcsvc6.DLL C:\Windows\System32\dhcpcsvc6.DLL 6.3.9600.16384
dhcpcsvc.dll C:\Windows\System32\dhcpcsvc.dll 6.3.9600.16384
mswsock.dll C:\Windows\System32\mswsock.dll 6.3.9600.16384
dnsapi.dll C:\Windows\System32\dnsapi.dll 6.3.9600.16423
rasadhlp.dll C:\Windows\System32\rasadhlp.dll 6.3.9600.16384
NapiNSP.dll C:\Windows\System32\NapiNSP.dll 6.3.9600.16384
pnrpnsp.dll C:\Windows\System32\pnrpnsp.dll 6.3.9600.16384
nlaapi.dll C:\Windows\System32\nlaapi.dll 6.3.9600.16384
winrnr.dll C:\Windows\System32\winrnr.dll 6.3.9600.16384
wshbth.dll C:\Windows\System32\wshbth.dll 6.3.9600.16384
cryptsp.dll C:\Windows\System32\cryptsp.dll 6.3.9600.16384
rsaenh.dll C:\Windows\System32\rsaenh.dll 6.3.9600.16384
bcrypt.dll C:\Windows\System32\bcrypt.dll 6.3.9600.16384
00000003() Unknown
[Frames below may be incorrect and/or missing]
> MyDesktop.dll!HandleModifyEvent(...) Line 159 C
MyDesktop.dll!ProcessFSEvent(...) Line 79 C
MyDesktop.dll!NSFileSysEventProcessor(void * lpParam=0x01adf324) Line 59 C
MyDesktop.dll!thread_first_breath(sThrdInfo * psParam=0x009d2848) Line 1119 C
msvcr110d.dll!_callthreadstartex() Line 354 C
msvcr110d.dll!_threadstartex(void * ptd=0x009ff308) Line 337 C
kernel32.dll!7790495d() Unknown
ntdll.dll!77b498ee() Unknown
ntdll.dll!77b498c4() Unknown
在合理的假设内,此代码不会生成此错误。这个数组的大小短了 1,但它的长度仍然是 260,这对于示例来说已经足够了。
此类访问违规强烈暗示存在野生商店。该函数的一个或多个指针参数已损坏,并在使用时触发访问冲突。
正如评论中所指出的,“在位置 0x000000nn”性质的访问冲突强烈表明对距对象开头偏移 nn 字节的结构或类成员的 NULL 指针取消引用。有时它是一个指针,其中存储了一个小整数。有时它会是一个已增加的空值。所有这些都强烈暗示数据在某个地方被覆盖。