IPB

Welcome Guest ( Log In | Register )

> Bug: Stack Overflow When Using Function Pointers
manuel123
post Sep 29 2007, 02:16 PM
Post #1


Regular
*

Group: EstablishedMember
Posts: 20
Joined: 21-September 05
Member No.: 829



Bug description:
-------------------
The -swcs option does not work correctly together with function pointers.
The call tree is not parsed correctly together with function pointers.

With "-swcs 0 1" the following code compiles correctly. With"-swcs 2 1" the compiler uses the hardware stack for both, the call to __fptr and the calls of fptr0..4(). This results in a stack overflow during the call of fptr4().

Steps to reproduce:
-----------------------

#include <system.h>

void (*fptr0)();
void (*fptr1)();
void (*fptr2)();
void (*fptr3)();
void (*fptr4)();

void test4() {
}
void test3() {
fptr4();
}
void test2() {
fptr3();
}
void test1() {
fptr2();
}

void test0() {
fptr1();
}

void main() {
fptr0 = test0;
fptr1 = test1;
fptr2 = test2;
fptr3 = test3;
fptr4 = test4;

fptr0();

while(1);
}


Expected behaviour:
The program should not produce a stack overflow.

Is the problem 100% reproduceable:
Yes.

IDE version: 6.81
Compiler: BoostC,
Compiler version: boostc.pic16.exe / v6.81
Target device: PIC16F88
OS: WinXP

Comments:
It seems that the call tree is not parsed through the __fptr function. If this is true, function pointers should be only compiled with "-swcs 0 1" or "-swcs 1 1" unless their use is very limited and the programmer takes care about stack overflows.

BR
manuel123
update Picpack 3.0 Released
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 3rd September 2010 - 02:47 PM