简体   繁体   English

运行时检查失败#2-MFC应用程序上变量'osvi'周围的堆栈已损坏

[英]Run-Time Check Failure #2 - stack around the variable 'osvi' was corrupted on mfc application

I've been searching around the internet and I have no idea why this happens, it's not really an obvious array issue. 我一直在互联网上搜索,我不知道为什么会这样,这并不是一个明显的阵列问题。

Here's the function: 功能如下:

BOOL IsOsCompatible()
{
    BOOL retVal = 0;
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    GetVersionEx(&osvi);
    if(osvi.dwMajorVersion == 6)
    {
        if(osvi.dwMinorVersion == 0)
        {
            if(SendErrorM("This program has not been tested on Windows Vista(TM).\nAre you sure you want to use it?",MB_YESNO) == IDYES)
                retVal = 1;
        }
        else if(osvi.dwMinorVersion == 1)
        { 
            retVal = 1;
        }
        else if(osvi.dwMinorVersion == 2)
        {
            if(SendErrorM("This program has not been tested on Windows 8(TM).\nAre you sure you want to use it?",MB_YESNO) == IDYES)
                retVal = 1;
        }
    }
    else
        SendErrorM("Your windows verison is incompatible with the minimum requirements of this application.",NULL);

    return retVal;

}

Any ideas? 有任何想法吗?

An OSVERSIONINFOEX is larger than an OSVERSIONINFO , so OSVERSIONINFOEX大于OSVERSIONINFO ,因此

    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

will write zeroes "outside" (around) osvi . 将在osvi “外部”(周围)写入零。

You want 你要

OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

or (often safer) 或(通常更安全)

OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(osvi));

The extra X is your problem: 多余的X是您的问题:

OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

Windows A, W and X suck. Windows A,W和X很烂。

Avoiding Macros : 避免宏

template <typename T>
inline void zero_memory(T& m) {
    std::memset(&T, 0, sizeof(T));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行时检查失败 #2 - 变量“应用程序”周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'application' was corrupted 运行时检查失败#2-变量“ z”周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable ''z" was corrupted 运行时检查失败2:变量&#39;expression&#39;周围的堆栈已损坏 - Run-Time Check Failure #2: Stack around the variable 'expression' was corrupted 运行时检查失败#2-变量&#39;ap&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'ap' was corrupted 运行时检查失败 #2 - 变量“normalIndex”周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'normalIndex' was corrupted 错误:运行时检查失败 #2 - 变量周围的堆栈已损坏 - ERROR: run-time check failure #2 - stack around the variable was corrupted 运行时检查失败#2-变量&#39;projectAverage&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'projectAverage' was corrupted 运行时检查失败#2-围绕变量&#39;&#39;的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable '' was corrupted 运行时检查失败#2-变量&#39;seqA&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'seqA' was corrupted 运行时检查失败#2-变量&#39;k&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'k' was corrupted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM