This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated7年前。Learn more
在C i.e缓冲区溢出中读取一些文本并尝试写入超过数组大小的内容。文本表明,当数组长度为5时,每当您试图写array[5]时,就会出现分段错误,但在使用下面的代码时,我似乎没有得到。代码实际运行。
#include <stdio.h>
#include <string.h>

int main ()
{
    int i;
    int array[5] = {1, 2, 3, 4, 5};
    for (i = 0; i <= 255; i++)
    {
        array[i] = 10;
    }
    int len = sizeof(array) / sizeof(int);
    printf("%d\n", len);
    printf("%d\n", array[254]);
}

执行最后一条语句时,将打印10。我想知道这是一个漏洞还是有什么东西我遗漏了。我在macbook pro上运行iterm2的代码。

最佳答案

写得过去时是不明确的行为——任何事情都有可能发生。

关于c - Mac OSX上是否可以使用此缓冲区溢出?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11058441/

10-12 00:23
查看更多