【发布时间】:2012-12-17 08:10:42
【问题描述】:
我使用了一些函数,这个函数返回LPWSTR类型的变量(wchar_t*)
在调试器中,我查看此变量并看到错误“0x2e(地址 0x2e 越界)” 当我对其变量进行一些操作时,我的程序终止了。
我不能改变被调用的函数,我没有它的源代码。
我的问题是:c/c++ 语言是否具有在调用错误变量之前检查情况的功能?我尝试尝试/捕获块,但没有帮助。
请原谅我的英语,感谢您的帮助
编辑:
有错误的代码片段
PCERT_EXTENSION pCe = CertFindExtension(szOID_CRL_DIST_POINTS, pCertInfo->cExtension, pCertInfo->rgExtension);
if (pCe) {
PCRL_DIST_POINTS_INFO pCrlDistPointsInfo = NULL;
PCRL_DIST_POINT *pCrlDistPointsPtr = NULL;
PCRL_DIST_POINT pCrlDistPoints = NULL;
DWORD pdwCrlDistPoints = sizeof (CRL_DIST_POINTS_INFO);
if (!CryptDecodeObjectEx(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
szOID_CRL_DIST_POINTS,
pCe->Value.pbData,
pCe->Value.cbData,
CRYPT_DECODE_ALLOC_FLAG,
(PCRYPT_DECODE_PARA) NULL,
&pCrlDistPointsInfo,
&pdwCrlDistPoints)) {
printf("\n\nCannot decode CRL URL.\n\n");
}
if (pCrlDistPointsInfo) {
pCrlDistPointsPtr = (PCRL_DIST_POINT*) pCrlDistPointsInfo->rgDistPoint;
if (pCrlDistPointsPtr && pCrlDistPointsInfo->cDistPoint > 0) {
findCDP = true;
fwprintf(pFile, L"^^");
for (int i = 0; i < pCrlDistPointsInfo->cDistPoint; i++) {
pCrlDistPoints = &pCrlDistPointsInfo->rgDistPoint[i];
if (pCrlDistPoints) {
LPWSTR str = (LPWSTR) pCrlDistPoints->DistPointName._empty_union_.FullName.rgAltEntry->_empty_union_.pwszURL;
//printf("last error= 0x%08X", GetLastError());
fwprintf(pFile, str);//PROGRAM TERMINATED HERE!!!
fwprintf(pFile, L";");
}
printf("%d\n",i);
}
}
free(pCrlDistPointsInfo);
}
}
【问题讨论】:
-
这在你的问题中是什么意思,什么错误:在调试器中我查看这个变量并看到错误“0x2e”?
-
这个函数的文档对返回值有什么说法?
-
它可能是使用低地址作为错误代码。阅读文档。
-
地址 0x2e 越界,标签中未显示值,我已修复
-
正确的方法是调试各个函数中的值被错误修改为
error "0x2e (Address 0x2e out of bounds)"的原因。可以修改此变量的所有方式以及修改它的人,而不是在函数调用之前检查不正确的值。
标签: c++ c memory certificate