Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a stack overflow on a compiled stack really impossible?

Tags:

c

testing

pic

xc8

When I have finished a software, I carry out a stack overflow test at the end. Why don't I have to do this with a compiled stack?
Are overflows really completely impossible here or only very rare?

like image 831
Mike Avatar asked Sep 19 '25 00:09

Mike


1 Answers

The XC8 "compiled stack" isn't really a stack at all, in the sense of pushing and popping. It holds the kind of data that would traditionally be allocated "on the stack" - local variables - but it doesn't grow. There's no stack pointer. Everything is just allocated at a fixed address. The "stack" can't grow past its limits if it doesn't grow in the first place.

This of course runs into other limitations not found with traditional stack allocation. For example, functions that use the compiled stack can't be called recursively. All calls to such functions have their local variables allocated at the same addresses, so if you tried to make a recursive call, it'd be stomping over the original call's local variables.

You can read more in the XC8 C Compiler User's Guide, particularly section 5.5.2.2.1, "Compiled Stack Operation".

like image 122
user2357112 supports Monica Avatar answered Sep 20 '25 15:09

user2357112 supports Monica