【发布时间】:2011-12-19 10:09:06
【问题描述】:
编辑: 亲爱的未来读者,std::string 与问题无关。这是一个未终止的数组。
简而言之,问题在于向仅包含 C 的程序添加单个 std::string 的声明会导致错误“访问冲突读取位置 0xffffffffffffffffe。”
在下面的代码中,如果声明 std::string 的行被注释掉,程序运行完成而没有错误。但是,如果该行留在程序中(未注释),则程序会因上述访问冲突错误而崩溃。当我在 VS2010 调试器中打开正在运行的程序时,调用 ldap_search_sA() 时发生了访问冲突。
请注意,声明的 std::string 从未使用过。不必使用它来导致访问冲突。简单地声明它会导致访问冲突。
我怀疑它与 LDAP 代码无关,但我可能是错的。
int main()
{
try {
// Uncommenting the next line causes an Access Violation
// at the call to ldap_search_sA().
// std::string s;
LDAP* pLdapConnection = ldap_initA("eu.scor.local", LDAP_PORT);
ULONG version = LDAP_VERSION3;
ldap_set_option(pLdapConnection, LDAP_OPT_PROTOCOL_VERSION, (void*) &version);
ldap_connect(pLdapConnection, NULL);
ldap_bind_sA(pLdapConnection, NULL, NULL, LDAP_AUTH_NTLM);
LDAPMessage* pSearchResult;
PCHAR pMyAttributes[2];
pMyAttributes[0] = "cn";
pMyAttributes[1] = "description";
ldap_search_sA(pLdapConnection, "dc=eu,dc=scor,dc=local", LDAP_SCOPE_SUBTREE, "objectClass=computer)", pMyAttributes, 0, &pSearchResult);
} catch (...) {
printf("exception\n");
}
return 0;
}
【问题讨论】:
-
我不知道这个 LDAP 的东西,但我怀疑你在某处调用 Undefined Behavior 并且该字符串的定义(!) 只是使它表现为一个 AV。
-
好的,所以您认为这实际上是对 LDAP 的不当使用,我应该深入了解一下吗? (如果是“是”,则无需回答。)
-
是的,我相信这一点,同时班塔尔也发现了问题所在。
标签: c++ visual-studio-2010 access-violation