if I could harm my personal files (videos, photos, office files etc.)
Windows programs run in the context of the current user, and can perform any action of the current user. This means it could edit and delete your personal files.
Generally for a program to go rogue, it would need to have the activity within it. A program which deletes files, can more easily start accidentally deleting files.
A program which edits files can make dodgy edits.
This is not a pre-requisite, as once it stops executing outside of your design, anything could happen.
if I could harm my system?
For your system to be harmed, you would need to be running as administrator. That gives the program the ability to do any action which an adminstator could do, which could include serious damage to your machine.
There is one further stage, which is system
, which has complete control on the machine, more than an administator.
Is it likely?
Whilst it is possible, it is not very likely. The likelihood for modern programs is they crash before they corrupt files other than they are currently opening, however there are things which you can do to make the damage less-likely or more limited.
If you have significant files for your user, then consider switching to a different account for development. This would ring-fence the damage an errant program would cause.
Ensure you don't run with User-access-protection turned off. This limits your programs ability to administrate your machine.
- Consider an alternative platform, the
raspberry-pi
, or Intel compute stick offer a cheap platform which can be re-built if things go wrong.
What happens in this case?
Assuming it gets stuck in a loop, without properly reading data (probably scanf() returning 0).
The array gets filled up with all 100 elements, and then starts corrupting the stack.
There are 2 plausible memory layouts (windows x86/x86-64).
+---------+
| return |
| from |
| main |
+---------+
|hero[99] |
+---------+
|hero[98] |
+---------+
|hero[97] |
+---------+
| ... |
and
+---------+
| return |
| from |
| main |
+---------+
| k |
+---------+
|hero[99] |
+---------+
|hero[98] |
+---------+
|hero[97] |
+---------+
| ... |
In the first case, the array gets over-run, and the return address is modified. There is code built into normal compiles (security cookie), which would detect this, and the result is a crash before bad stuff happens.
In the second case, the memory for variable k gets overwritten with one of the array writes. This then sends k to some kooky place, and random memory is overwritten. This could corrupt the program data, but most likely the first attempt at non-natural k (outside of 0-99) would result in a crash.
The likely failure was that you printed out a control code such as a beep - that causes strange behavior, and is consistent with what you saw - I don't think anything bad happened for you.