The stackoverflow.com logo suggests a certain description of a stack overflow. I don't mean to say that logos must be correct in what they depict. The logo is perfectly all right as a logo.
But how apt is it as a description of the "real" stack overflow? I mean, if the stack overflow condition is detected as an error, the picture is not right. And if it is NOT detected, again the picture is not right. Is what I say correct?

12 Answers
12

The logo itself is like a real stack overflow in some ways and not in others.

The colors going from gray to orange maybe signifies danger in the logo as you go higher in the stack, a better representation for a stack overflow though, would be to have all elements completely gray until it reached the maximum size, and then it would turn red for everything above it.

The logo correctly shows that the elements of the stack are exceeding the stack limit.

Usually your program will crash or you will get a segmentation fault as soon as you exceed your stack. In this way the logo is not like a real stack overflow. Because it shows many items on top of the stack.

The logo properly displays that it is a stack:

The logo has a container for the elements in the stack

The logo shows that there are elements in the stack.

The logo shows that the bottom of the stack is closed, meaning things enter it first in last out.

About what a stack overflow is:

A stack has a maximum address that should not be exceeded. This maximum address can be exceeded by pushing something onto the stack. The size of the stack determines what this maximum address can be. You can set this stack size for your programs.

As an aside, the opposite is a stack underflow, where you try to pop from the stack when nothing is on it, resuling in going under the minimum address that cannot be exceeded.

Here is an example of a stack overflow:

int functionCall()
{
char x[102400000]; // <--- Just an example, may not overflow if stack is very large
//...
return 0;
}

Here is another example of a stack overflow, In this example the stack is exceeded because every function call pushes something on the stack:

But luckily there is a comment trail.
–
Brian R. BondyNov 16 '08 at 17:05

In your first example, "char x[102400000];" may be compiler optimized to the heap since the program exits when main does and while scoped locally, it may as well be global for the length of time it's occupied. You might move it to a function call to be more explicit.
–
Adam DavisNov 18 '08 at 16:09

Nitpick time!! On Windows, at least, extra stack space is provided after a stack overflow, so that the resulting exception can be handled with code that needs the stack. In this light, the logo is still somewhat accurate, because the items beyond the top of the stack are representative of this extra buffer reserved for exception handling purposes.
–
that one guyNov 10 '09 at 3:41

Well my friends, years ago, back in the dark ages of computing, a colleague came to me with a problem. His code was randomly crashing, and he couldn't figure out where the bug was.

By crash I mean write random characters to random spots on the screen, lock up, and require physical powering down. Yes, this was the world of DOS, the IBM pc, back when we ran without virtual memory or "protected" memory segments.

So it turns out my colleague was running with the default 4k stack. Yes, 4 kilobytes. Get out your magnifying glass.

Back in those days, the stack started at one end of memory. Code went at another. Heap went at another. The heap and stack kind-of worked up/down toward each other. When they met, it was "troublesome".

Only my colleague's compiler put his compiled binary code up at the end of the stack.

And he declared a large array of floats on the stack. A very large array, for his stack size. It took up a little over 3k.

Eventually, when his function call tree got deep enough, he overwrote his code.

Eventually, he called that code.

My friends, THAT is a stack overflow.

You people today, with your virtual memory and coredumps. You have it easy!

Generally a stack is a Last In - First Out (FIFO) structure. In most systems the storage allocated to the stack is finite in nature. A common way is to segment the address space such that the heap grows from one end address space and the stack from the other end. when the number of elements in the stack exceed the storage space it is said to overflow.

There are CPU stacks keeping track of various values, there are stack frames for tracking function calls in a language run-time and various other stacks keeping track of temporary values. the reason the stack is used is because allocating memory on the stack really just copying a value and incrementing a pointer just past the size of the pushed element.

<strike>they're too mean here. this is a correct description of whatmakes a stackoverflow bad for the program. but they still vote this down even after he corrected the FIFO error.</strike> I see now the correction was done by someone else :)
–
Johannes Schaub - litbNov 16 '08 at 17:52

Warren, the use of a heap growing toward the stack, or even having two stacks that grow toward each other inside of a large memory segment is not an uncommon implementation, especially when stacks were implemented entirely in software.
–
orcmidNov 17 '08 at 2:17

And Warren, it is useful for the area that is used for heap blocks to grow towards an approaching stack. Sometimes this involves reorganization of the heap from time to time so that any holes are moved to the space in front of the approaching stack. Or, depending on situation, fail on collision.
–
orcmidNov 17 '08 at 2:21

I think as a depiction of cookies overflowing from a cup it is definitely misleading
–
AydyaNov 16 '08 at 17:10

Well, it's just a logo, no? It's difficult to depict an exceptional condition in a technical setting, like an overflow of the stack of a process, with a simple picture. It doesn't mean to be accurate. The very name of this site is also symbolic: SO deals with programming, not with flaws like s.o.'s
–
Federico RamponiNov 16 '08 at 18:28

I don't know how to compare the logo to a real stack overflow. Strictly speaking, a stack overflow could apply to any kind of stack, not just the function call stack that the two existing answers refer to. As they describe, a stack overflow happens when a stack has more things pushed onto it than its fixed allocation of memory can accommodate. In that sense, the logo is completely wrong because the items wouldn't curve as they overflowed, nor would they change color, because they wouldn't have a geometric orientation or a color to begin with.

In any case, I always thought the stackoverflow.com name referred more to the problem of developers being overwhelmed with things to do, things to learn, and in general, too many mental contexts over the course of a day. In that sense, there's nothing technical about the name at all...

The logo does not accurately depict a computational stack overflow, but it gives a sense of the words "stack" and "overflow." As a logo goes it's great, for several reasons:

It's easy to recognize, so branding is solid.

It depicts the name, and thus the association is reasonably solid in a user's mind.

It's easy/cheap to render in color, black and white, and low and high resolution devices. (ie, no information is lost when the logo is monotone or grayscale)

Compression works well on it, so it's cheap to transmit, store, cache, buffer, render, etc

As far as technical issues:

A stack overflow results in other memory being overwritten - the logo suggests that the container just stops accepting new items, and they are lost. The reality is much more insidious in nature - the new items are destructive to existing data near the memory location of the stack. Think of a stack as containing antimatter, and the rest of the program consisting of matter. When the stack overflows, it 'spills' onto the rest of the program and Bad Things Happen (TM).

A stack, in most architectures, grows downward from the top - the memory location of the stack generally starts at a higher address, say 0xFFFF and the stack pointer decrements down to 0x0000 (the heap grows up, in this way there's a buffer in between so that stack or heap overflows have less impact), so visually the logo is upside down. Unless, of course, you look at memory as a list starting with 0x0000, where it would appear that a stack "grows upward by decreasing its memory pointer":

0x0000

0x0001

...

0xFFFE

0xFFFF

This is, of course, a matter of perspective, and results in much confusion. In general one should refer to a stack as "decrementing" or "incrementing" to avoid such confusion.

The logo depicts a stack of even sized items. Stacks can (and do) hold all sorts of oddly sized and shaped things - there is no constant typical item size.

But, at the end of the day, a logo is about branding. It's not meant to be a teaching object, and this one is very good for it's purpose.

A stack overflow occurs when the pile of papers to be handled in your inbox gets so high that it cascades sideways onto the floor, causing a complete brain reset in panic at dealing with so many issues.

The friction of the paper sliding sideways causes it to burst into flames, thus the change in color to a fiery orange as the stack gets higher and higher.

Technically, for a call stack a "stack overflow" is detected when the CPU issues a write to the stack at a higher address than "allowed", which leads to an exception being raised to the operating system. The range of "allowed" addresses is determined by the memory tables for that process and is set up by the operating system.
When creating a thread in windows, you can decide what size the stack should have. (Even though, the physical memory is probably not committed to this stack until actually required.)

"an exception being raised to the operating system" assuming a protected operating system. On some systems, you'll just keep merrily onward, having corrupted some kernel structure, or another thread's stack, or whatever.
–
onebyoneNov 16 '08 at 16:27

Thanks, that's very true.
–
HugoNov 16 '08 at 16:30

1

On most CPUs, a stack actually grows down, from higher addresses to lower. This seems counter-intuitive, but made a lot of sense back in the days when the stack, data, & code often shared the same address space. Data could grow up & the stack could grow down. An overflow meant overwriting data.
–
P DaddyNov 16 '08 at 17:58

Thinking further back, consider a cafeteria line that has a special stacker for clean trays at the start of the line. The stack has a spring mechanism so that the stack will sink into the container as more clean trays are placed on top.

At some point, the stack can't descend any farther and new trays will start to pile up higher and higher above the normal height maintained by the stacking mechanism. Keep this up and the stack will be unstable and topple.

This is not unlike the stack used diagramatically in the Stack Overflow logo.

There is another case too, referred to as stacker or hopper overflow.

In the era of punched cards, card readers and card punches attached to computers would often stack their output face down where it could be removed from the output hopper with the cards in proper sequence. The stack of output or already-read cards was usually fed onto a spring-loaded piston under a plate that could move up and down inside of a channel that kept the cards from falling out. (You could remove the cards sideways from the vertical hopper.)

When it was sensed that the plate had descended too far, there was a mechanical mechanism (patented by IBM) involving a spring-loaded toggle switch. When the toggle was thrown by the weight of the descending stack of cards, the card transport would be stopped until an operator removed the stack from the hopper that overflowed.

Thanks for informative answers, incisive comments and eloquent markdowns. I clarify again: the logo is good enough as a logo. My question was only about whether it depicted the stack overflow condition properly.

I appreciate the historical(nostalgic for me too) references to the various connotations of stack.