I want this to crash, but it doesn't

前端 未结 4 1199
不知归路
不知归路 2021-01-17 01:06

seriously.. I\'m an old hacker from the 80\'s and with some spare time on my hands thought I\'d \'C\' what the fuss is about

( my background is Forth, which does thi

4条回答
  •  心在旅途
    2021-01-17 01:50

    Typically memory is allocated in 4 kB pages. Therefore there is some extra space after the last variable, and your buffer overrun goes undetected. If, however, there was another variable after your members array and you wrote to members[4], that another variable would get corrupted.

    Tools like valgrind and dmalloc are often used to detect buffer overruns. They work by allocating special guard regions around your variables and checking that no-one has written there.

提交回复
热议问题