我在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
答案 0 :(得分:3)
在合理的假设范围内,此代码无法生成此错误。这个数组的大小只有一个,但它的长度仍为260,这就足够了。
此类访问冲突强烈暗示了野生商店。该函数的一个或多个指针参数已损坏,并在使用时触发访问冲突。
如果您可以使用最少的完整验证示例(https://stackoverflow.com/help/mcve)重现问题,那么将会有很少人帮您找到您的错误。但到那时你会自己找到它。
正如评论中所指出的那样,在位置0x000000nn"的访问违反了"的性质;强烈指示对结构或类成员的NULL指针解除引用,该结构或类成员是从对象的开头偏移的nn个字节。有时候它会是一个存储了一个小整数的指针。有时它会增加一个null。所有强烈暗示数据都被覆盖在某处。