Stack overflow

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 implement tail-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

void f(void); void g(void); int main(void) { f(); return 0; } void f(void) { g(); } void g(void) { f(); }

f() calls g(), which in turn calls f() and so on. Eventually, the stack overflows.

;Large stack variables

// Large Array Allocation on the stack:

int main(void) { int n [10000000] ; /* array is too large */ int j =0; /* j's address exceeds the stack's limits, error */ return 0; }

ee also

*Stack buffer overflow
*Heap overflow
*Buffer overflow
*Call stack

References


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Stack Overflow — URL: www.stackoverflow.com Коммерческий: да Тип сайта: Система вопросов и ответов …   Википедия

  • Stack Overflow — Pufferüberläufe (engl. buffer overflow) gehören zu den häufigsten Sicherheitslücken in aktueller Software, die sich u. a. über das Internet ausnutzen lassen können. Im Wesentlichen werden bei einem Pufferüberlauf durch Fehler im Programm zu große …   Deutsch Wikipedia

  • Stack overflow — Dépassement de pile En informatique, un dépassement de pile ou débordement de pile (en anglais, stack overflow) est un bogue causé par un processus qui, lors de l écriture dans une pile, écrit à l extérieur de l espace alloué à la pile, écrasant… …   Wikipédia en Français

  • Stack Overflow — Pour les articles homonymes, voir Stack overflow (homonymie). Stack Overflow …   Wikipédia en Français

  • Stack overflow (homonymie) — Cette page d’homonymie répertorie les différents sujets et articles partageant un même nom. Stack overflow peut signifier: dépassement de pile une erreur de programmation. Stack Overflow un site web de question réponse. Catégorie : Homonymie …   Wikipédia en Français

  • Call stack overflow — Dépassement de pile En informatique, un dépassement de pile ou débordement de pile (en anglais, stack overflow) est un bogue causé par un processus qui, lors de l écriture dans une pile, écrit à l extérieur de l espace alloué à la pile, écrasant… …   Wikipédia en Français

  • Stack Exchange Network — Stack Exchange Network  сеть вебсайтов для работы с вопросами и ответами в различных областях. Сайты позволяют пользователям задавать вопросы и отвечать на них. Путем учёта активной деятельности, происходит голосование за вопросы и ответы,… …   Википедия

  • Stack buffer overflow — In software, a stack buffer overflow occurs when a program writes to a memory address on the program s call stack outside of the intended data structure; usually a fixed length buffer.cite web last = Fithen first = William L coauthors = Seacord,… …   Wikipedia

  • Stack (data structure) — In computer science, a stack is an abstract data type and data structure based on the principle of Last In First Out (LIFO) . Stacks are used extensively at every level of a modern computer system. For example, a modern PC uses stacks at the… …   Wikipedia

  • Stack-based memory allocation — Stacks in computing architectures are regions of memory where data is added or removed in a Last In First Out manner.In most modern computer systems, each thread has a reserved region of memory referred to as its stack. When a function executes,… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”