我得到了一个静态代码分析
错误C6001,使用未初始化的内存“zExplicitAccess.Trustee.ptstrName”
VS2022(v143)升级后的以下代码。有谁能建议一下这里出了什么问题,以及如何解决呢?
C++语言标准- ISO C++17标准
EXPLICIT_ACCESS zExplicitAccess[4];
ULONG dwIndex;
/*----- Initialize structure for new access -----*/
memset(&zExplicitAccess[0], (char)0, sizeof(EXPLICIT_ACCESS) * 4);
for (dwIndex = 0; dwIndex < 3; ++dwIndex)
{
zExplicitAccess[dwIndex].Trustee.TrusteeForm = TRUSTEE_IS_SID;
zExplicitAccess[dwIndex].Trustee.ptstrName = (char *)_GetSidFromUser(zExplicitAccess[dwIndex].Trustee.ptstrName, NULL);
}
for (dwIndex = 0; dwIndex < 3; ++dwIndex)
{
free(zExplicitAccess[dwIndex].Trustee.ptstrName);// **Error 6001 here**
}
发布于 2021-12-21 18:59:48
若要修复VS2022中的静态代码分析错误,请将替换为delete。谢谢!
/*----- Convert user names to SIDS (to save time)-----*/
for (dwIndex = 0; dwIndex < 3; ++dwIndex)
{
zExplicitAccess[dwIndex].Trustee.TrusteeForm = TRUSTEE_IS_SID;
zExplicitAccess[dwIndex].Trustee.ptstrName = (char *)_GetSidFromUser(zExplicitAccess[dwIndex].Trustee.ptstrName, NULL);
}
/*----- Tidy up SIDS -----*/
for (dwIndex = 0; dwIndex < 3; ++dwIndex)
{
free(zExplicitAccess[dwIndex].Trustee.ptstrName); // C6001 error
}
https://stackoverflow.com/questions/70403430
复制相似问题