Search code examples
cbsod

Can bad C code cause a Blue Screen of Death?


I am a new coder in c, recently moved over from python, but still like to challenge myself with fairly ambitious projects (like a chess program), and have found that my computer suffers an unusual number of BSODs, both when I am running a program and not (admittedly, attempting to use the entirety of my memory as a hash table may not have been the greatest idea).

So my question is, are these most likely caused by my crappy c code, or is it more likely that my 3 year old, overworked laptop is the culprit? If it could be the code, what are the big things I should avoid doing so as to prevent this?


Solution

  • BSOD usually contains some information as to what caused it.

    What information it contains, and how exactly it is displayed depends on the version of Windows you are running.

    As can be seen from the list here:
    https://hetmanrecovery.com/recovery_news/bsod-errors

    Most BSOD errors come from device / driver / kernel code, and not from your typical userland program.

    That said, it might be possible to trigger BSOD if your code uses particularly low level windows API, especially if you run it with administrator privileges.

    Note, that simply filling up memory will result in allocations for your program failing, and possibly your program, but not the whole OS crashing.
    Also, windows does place limits on how much an individual process can allocate.

    One final note:

    "3 year old laptop" does not provide enough information to tell anything about your hardware, since there are different tiers of laptops available, and some of the high end 3 year old ones will still be better performing then a mid tier one bought yesterday.

    As a troubleshooting measure, I would recommend backing up your data, making a clean install of your OS (aka "format the machine"), then making sure all your drivers are up to date.

    You may also want to try hardware diagnostic tools, such as memtes86, check SMART on your storage, etc.