0

I'm currently learning about stack and heap memory in C++. I have read that heap overflows are 'dangerous' as they can overwrite other code which can obviously mess up the program: dangers of heap overflows?

My question is whether anything will happen to the rest of my computer? When I'm doing practice questions/experimenting with heap memory, I don't want to screw up my laptop (I broke my previous one). I don't mind my heap practice programs not working as long as I can still run other programs like nothing happened. I have a feeling modern OSes have protections against overflows, and this question may seem naive, but I'm too scared for my laptop, so don't judge.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    If you're not coding on old-school MSDOS, an embedded O/S or something equally bare-bones, there are such protections in place. You can mess up your own program's execution, but nothing else. In the good old days on the ancient PC's, a null pointer practically invited you to overwrite the most sensitive interrupt request pointers. Needless to say, hilarity ensued! Though I never managed to wreck the hardware or force an O/S reinstall from scratch: it's harder than you may think. – Pontus Gagge Apr 03 '21 at 11:20
  • your question is basically a duplicate of the one you [link](https://stackoverflow.com/questions/29998096/dangers-of-heap-overflows). You are asking specifically about harm that can be done to things outside of the scope of your program, but the other question is not limited to harm only within the scope of the running program – 463035818_is_not_an_ai Apr 03 '21 at 11:41
  • " is whether anything will happen to the rest of my computer?" - yes, if it enrages user enough – user3124812 Apr 03 '21 at 14:11

1 Answers1

0

On a modern computer with memory protection, the worst you can do is crash your own program. (If your program was running continuously and accepting data from the internet, it might also provide a way for a hacker to access your computer, but that scenario seems unlikely for what you are doing)

Even on older OS’s without memory protection, the worst you could do was corrupt the contents of RAM, possibly crashing the OS, in which case a reboot would clear the fault.

In no case will mismanagement of heap memory damage the hardware.

Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234