- Stack overflow
In software, a stack overflow occurs when too much memory is used on the
call stack . In many programming languages the call stack contains a limited amount of memory, usually determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When too much memory is used on the call stack the stack is said to overflow; typically resulting in a program crash. cite web
last = Burley
first = James Craig
title = Using and Porting GNU Fortran
url= http://sunsite.ualberta.ca/Documentation/Gnu/gcc-2.95.2/html_node/g77_597.html
date = 1991-06-01 ] This class of software bug is usually caused by one of two types of programming errors.cite web
last = Danny
first = Kalev
title = Understanding Stack Overflow
url=http://www.devx.com/tips/Tip/14276
date = 2000-09-05 ]Infinite recursion
The most common cause of stack overflows is excessively deep or infinite recursion. Languages, like
Scheme , which implementtail-call optimization allow infinite recursion of a specific sort —tail recursion — to occur without stack overflow. This works because tail-recursion calls do not take up additional stack space.cite web
title = An Introduction to Scheme and its Implementation
url=http://www.federated.com/~jim/schintro-v14/schintro_73.html
date = 1997-02-19 ]Very large stack variables
The other major cause of a stack overflow results from an attempt to allocate more memory on the stack than will fit. This is usually the result of creating local array variables that are far too large. For this reason arrays larger than a few kilobytes should be allocated dynamically instead of as a local variable.cite web
last = Feldman
first = Howard
title = Modern Memory Management, Part 2
url=http://www.onlamp.com/pub/a/onlamp/2005/11/23/memory-management-2.html
date = 2005-11-23 ]Stack overflows are made worse by anything that reduces the effective stack size of a given program. For example, the same program being run without multiple threads might work fine, but as soon as multi-threading is enabled the program will crash. This is because most programs with threads have less stack space per thread than a program with no threading support. Similarly, people new to kernel development are usually discouraged from using recursive algorithms or large stack buffers.cite web
publisher=Apple Inc .
title = Kernel Programming Guide: Performance and Stability Tips
url=http://developer.apple.com/DOCUMENTATION/Darwin/Conceptual/KernelProgramming/style/chapter_5_section_5.html
date = 2006-11-07 ] cite web
last = Dunlap
first = Randy
title = Linux Kernel Development: Getting Started
url=http://www.xenotime.net/linux/mentor/linux-mentoring.pdf
date = 2005-05-19 ]C/C++/Objective C/Objective C++ examples
;Infinite recursion
f()
callsg()
, which in turn callsf()
and so on. Eventually, the stack overflows.;Large stack variables
ee also
*
Stack buffer overflow
*Heap overflow
*Buffer overflow
*Call stack References
Wikimedia Foundation. 2010.