C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-24-2009, 09:48 AM   #1
Registered User
 
Join Date: Oct 2009
Posts: 1
corrupted stack pointer

I have a thread A in my code. Even though the stack is not full, I sometimes see that I have an invalid value of the stack pointer (the stack pointer value is outside the stack size range for that thread) and see a stack overflow error. Any tips on what are the possible ways this could happen? and how I could possibly debug this?
Thx
Subbu
megadeath16 is offline   Reply With Quote
Old 10-24-2009, 10:08 AM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,862
The typical way for such a thing to happen is to go walking off the end of an array.
tabstop is offline   Reply With Quote
Old 10-24-2009, 11:13 AM   #3
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
Quote:
Originally Posted by tabstop View Post
The typical way for such a thing to happen is to go walking off the end of an array.
But that doesn't usually cause the stack pointer to point somewhere weird.

Normally, the only way the stack pointer could become invalid is if you entered an infinite recursion, or tried to allocate too big of an object on the stack.

Given that it crashes, I assume he's not just seeing the stack pointer from some other thread (it's easy to confuse yourself with the debugger) and in fact there is something wrong. I'd start by examining any recursive functions or functions which allocate large stack variables.

EDIT: If this is on Windows, there is a strange thing involving floating point that can result in a "stack overflow" (it's not, it's Windows messing up) but we'll get there when we get there...
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 10-24-2009, 01:52 PM   #4
Algorithm Dissector
 
iMalc's Avatar
 
Join Date: Dec 2005
Location: New Zealand
Posts: 2,746
One way in VS is to add a breakpoint to any loops of suspected infinitely recursive functions, that breaks at or after a certain number of hits.
But then, you haven't told us what environment you're using yet
__________________
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
iMalc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Following CTools EstateMatt C Programming 5 06-26-2008 10:10 AM
corrupted stack??? Abda92 C Programming 12 01-31-2008 03:05 AM
stack around the variable corrupted chintugavali C++ Programming 2 01-09-2008 01:01 PM
Run-Time Check Failure #2 - Stack around the variable 'novouser' was corrupted. IndioDoido C Programming 3 05-22-2007 11:42 PM
stack and pointer problem ramaadhitia C Programming 2 09-11-2006 11:41 PM


All times are GMT -6. The time now is 01:24 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22