A stackoverflow is when stack hits the heap and then stops. There are security issues associated with stackoverflow while a inifinite loop just keeps on running.
Someone asked in this in an interview and I answered stackoverflow. Is it correct?
A stackoverflow is when stack hits the heap and then stops. There are security issues associated with stackoverflow while a inifinite loop just keeps on running.
Someone asked in this in an interview and I answered stackoverflow. Is it correct?
I would tend to agree with you. A stackoverflow can cause problems outside of your immediate shell where an infinite loop just eats up processor time.
This is probably an example of a question with no right answer, though. They probably just wanted to see you process the question and give a well-thought out answer.
Security problem can be caused by SO, but it can be caused by anything. Infinite loop tends to cause also memory leak (not always, but often).
Buffer overrun is caused typically not the SO, but by overloaded buffer (tricking the code to overwrite its own return address, in ideal case to what we just sent to the buffer). However:
Both makes the program not working any more.
The difference is that in the SO, you have a stack trace and you know on the spot what the cause was. It is mostly easy to fix (the typical hotfix is to alter big stack allocations to dynamic, heap allocations, i.e. in C, you convert int x[BIG_BIG_NUMBER]
to int *x = malloc(sizeof(int) * BIG_BIG_NUMBER); ...; free(x);
.
In infinite loop, you have not this information, furthermore you have no easy way to know if a program is in infinite loop, or it is simply slow. Furthermore, the most important thing: you can easily debug the current state of the program, but you have no retroactive information about its previous states which caused it.
In these reasons, I believe SO is the better. Although it depends a lot on the circumstances. For example, SO caused by a recursive function and not by large stack allocations, can be about so problematic like the infinite loops.