gpt4 book ai didi

C++检查变量以解决越界问题

转载 作者:太空狗 更新时间:2023-10-29 20:05:22 27 4
gpt4 key购买 nike

我使用了一些函数,这个函数返回了LPWSTR类型的变量(wchar_t*)

在调试器中我查看这个变量并看到错误“0x2e(地址 0x2e 越界)”当我对其变量进行一些操作时,我的程序终止了。

我无法更改调用的函数,我没有它的源代码。

我的问题是:c/c++ 语言是否有函数在调用不正确的变量之前检查情况?我尝试尝试/捕获 block ,但它没有帮助。

请原谅我的英语问题,感谢您的帮助

编辑:

有错误的代码片段

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);
}
}

最佳答案

不,它没有。如果设置指向无效内存位置的指针,则每次访问该位置的对象都是未定义的行为。最有可能发生的是崩溃或某种内存损坏。

关于C++检查变量以解决越界问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13910440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com