stack-overflow

Stack overflow caused by recursive function

左心房为你撑大大i 提交于 2019-11-27 02:09:52
Being a beginner to C++ programming and computer systems architecture, I'm still learning the basics of C++. Yesterday I read about recursive function, so I decided to write my own, here's what I wrote : (very basic) int returnZero(int anyNumber) { if(anyNumber == 0) return 0; else { anyNumber--; return returnZero(anyNumber); } } And when I do this : int zero1 = returnZero(4793 ); it causes a stack overflow, however, if I pass the value 4792 as parameter, no overflow occurs. Any ideas as to why ? Whenever you call a function, including recursively, the return address and often the arguments

What is the difference between a stack overflow and buffer overflow?

社会主义新天地 提交于 2019-11-26 23:54:25
问题 What is different between stack overflow and buffer overflow in Programming ? 回答1: Stack overflow refers specifically to the case when the execution stack grows beyond the memory that is reserved for it. For example, if you call a function which recursively calls itself without termination, you will cause a stack overflow as each function call creates a new stack frame and the stack will eventually consume more memory than is reserved for it. Buffer overflow refers to any case in which a

What actually causes a Stack Overflow error? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-26 23:24:31
This question already has an answer here: What is a StackOverflowError? 13 answers I've looked everywhere and can't find a solid answer. According to the documentation, Java throws a java.lang.StackOverflowError error under the following circumstance: Thrown when a stack overflow occurs because an application recurses too deeply. But this raises two questions: Aren't there other ways for a stack overflow to occur, not only through recursion? Does the StackOverflowError happen before the JVM actually overflows the stack or after? To elaborate on the second question: When Java throws the

stackoverflow error in class constructor

故事扮演 提交于 2019-11-26 23:12:27
Please excuse what is probably a very basic question, but I am writing a program to store employee info and it works fine until it tries to set the info inside my employee class. It gives a stackoverflow error and I cannot figure out why. Thanks for any help. Main class: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner Input = new Scanner(System.in); System.out.println("Enter the number of employees to enter."); int employeeCount = Input.nextInt(); Input.nextLine(); Employee employee[] = new Employee[employeeCount]; String namesTemp; String

Windows: avoid pushing full x86 context on stack

最后都变了- 提交于 2019-11-26 22:58:02
问题 I have implemented PARLANSE, a language under MS Windows that uses cactus stacks to implement parallel programs. The stack chunks are allocated on a per-function basis and are just the right size to handle local variables, expression temp pushes/pops, and calls to libraries (including stack space for the library routines to work in). Such stack frames can be as small as 32 bytes in practice and often are. This all works great unless the code does something stupid and causes a hardware trap...

StackOverflowError when serializing an object in Java

自闭症网瘾萝莉.ら 提交于 2019-11-26 22:54:32
I am writing an application in Java using Swing. I am trying to implement functionality to save and load simulation states for at simulation i am running. The entire simulation is kept as an object, disconnected from Swing. I am trying to serialize my Simulation class with this code: public void saveSimulationState(String simulationFile) { try { Serializable object = this.sm; ObjectOutputStream objstream = new ObjectOutputStream(new FileOutputStream(simulationFile)); objstream.writeObject(object); objstream.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } But i get

How to debug: w3wp.exe process was terminated due to a stack overflow (works on one machine but not another)

人盡茶涼 提交于 2019-11-26 22:33:21
问题 The problem I have an ASP.NET 4.0 application that crashes with a stack overflow on one computer, but not another. It runs fine on my development environment. When I move the site to the production server, it throws a stack overflow exception (seen in event log) and the w3wp.exe worker process dies and is replaced with another. What I've tried so far For reference, I used the debug diagnostic tool to try to determine what piece of code is causing the overflow, but I'm not sure how to

Stackoverflow with Quicksort Java implementation

旧巷老猫 提交于 2019-11-26 22:04:20
问题 Having some problems implementing quicksort in java. I get a stackoverflow error when I run this program and I'm not exactly sure why. If anyone can point out the error, it would be great. si is the starting index. ei is the ending index. public static void qsort(int[] a, int si, int ei){ //base case if(ei<=si || si>=ei){} else{ int pivot = a[si]; int length = ei - si + 1; int i = si+1; int tmp; //partition array for(int j = si+1; j<length; j++){ if(pivot > a[j]){ tmp = a[j]; a[j] = a[i]; a[i

What is the difference between a segmentation fault and a stack overflow?

风格不统一 提交于 2019-11-26 21:52:23
For example when we call say, a recursive function, the successive calls are stored in the stack. However, due to an error if it goes on infinitely the error is 'Segmentation fault' (as seen on GCC). Shouldn't it have been 'stack-overflow'? What then is the basic difference between the two? Btw, an explanation would be more helpful than wikipedia links (gone through that, but no answer to specific query). kennytm Stack overflow is [a] cause, segmentation fault is the result. At least on x86 and ARM, the "stack" is a piece of memory reserved for placing local variables and return addresses of

Why am I getting a StackOverflowError exception in my constructor

China☆狼群 提交于 2019-11-26 21:38:55
问题 public class Cloning { Cloning c=new Cloning(); public static void main(String[] args) { Cloning c=new Cloning(); c.print(); } public void print(){ System.out.println("I am in print"); } } In the above code I have a simple class and a class level instance, I also have a local instance with the same name. When running the above code I get below exception : Exception in thread "main" java.lang.StackOverflowError at com.java8.Cloning.<init>(Cloning.java:6) 回答1: Your main method creates a Cloning