segmentation-fault

Assembly: C++ stack variable addresses different/wrong?

北城以北 提交于 2020-01-05 04:03:14
问题 I don't understand why getting the address of one variable is fine and the other gets me 0xD which then crashes due to writing a value at an invalid address (0xD in r.thefn(0); ). This is the output which shows the two variables not having a similar address. Here is what GDB showed and the assembly output. My x86 assembly isn't great (I have never written x86 assembly). I don't know if it shows enough information, but if I don't, can you tell me what else is required to debug this? Why is one

Why a segmentation fault occurs calling a function inside setjmp()?

倾然丶 夕夏残阳落幕 提交于 2020-01-05 03:55:08
问题 I do not understand why in the function middleFunc() , a segmentation fault is raisen when entry_point(arg) is invoked inside the if ( setjmp(middle) ) statement. #include <stdio.h> #include <setjmp.h> jmp_buf start,middle,end; void finalFunc(void *v) { printf("hello\n"); return ; } void middleFunc(void (*entry_point)(void *), void *arg) { //just debug : this does not cause segmentation fault entry_point(arg); if ( setjmp(middle) ){ //this casues the segmentation fault entry_point(arg); /

Segmentation fault in C++ using vectors

元气小坏坏 提交于 2020-01-04 05:19:11
问题 I'm having trouble with a segmentation fault caused by the following line: heapVec[currentsize] = *(new Node(d)); What am I doing wrong here? #include <vector> using namespace std; class Node { private: int data; public: Node(int); // ~Node(); }; class Heap { private: vector<Node> heapVec; int currentsize; public: Heap(); // ~Heap(); void insert(int); void extractMin(); void reduceKey(); }; Node::Node(int d) { data = d; } void Heap::insert(int d) { heapVec[currentsize] = *(new Node(d));

Initializing the D runtime on OS X

a 夏天 提交于 2020-01-04 04:20:12
问题 Edit: this seems to be a longrunning issue with no imminent solution: http://d.puremagic.com/issues/show_bug.cgi?id=8133 http://www.digitalmars.com/d/archives/digitalmars/D/Ideas_for_runtime_loading_of_shared_libraries._154126.html http://lists.puremagic.com/pipermail/dmd-internals/2011-December/002853.html There seems to be a problem with starting the d runtime in a d dylib loaded in a c program. Whenever I call Runtime.initialize() i get a segfault. C code: #include <stdio.h> #include

Segmentation fault with strcmp()

馋奶兔 提交于 2020-01-04 04:04:34
问题 if(strcmp(argv[2], NULL) == 0) I'm passing 3 command line arguments but I also want to run it with only 2 command line arguments with the above statement. But a segmentation fault error is being displayed. I also tried with if(argc < 3) but it also didn't work...same segmentation fault... 回答1: Why segmentation fault? Because of code if(strcmp(argv[2], NULL) == 0) , you are passing NULL as string pointer to strcmp() function; that try to deference at NULL to compare chars codes (e.g. acsii

Why Do I Get a Segmentation Fault with this C Code?

馋奶兔 提交于 2020-01-04 02:48:10
问题 This code gives me a segmentation fault: char *s1 = "String 1", *s2 = "String 2"; void swap(char **, char **); int main(void) { swap(&s1, &s2); return 0; } void swap(char **p, char **q) { char **tmp; *tmp = *p; *p = *q; *q = *tmp; } But if I change the body of the last function to this code it doesn't make any problems: char *tmp; tmp = *p; *p = *q; *q = tmp; I really don't understand why am I getting a segmentation fault with the first code. Thanks in advance. 回答1: Your tmp pointer is

Handling segfault signal SIGSEGV need to determine the cause of segfault using siginfo_t

独自空忆成欢 提交于 2020-01-04 02:11:18
问题 I'm making a wrapper for the pthread library that allows each thread to have its own set of non-shared memory. Right now the way c is set up if any thread tries to rwe another threads data, the program segfaults. This is fine, I can catch it with a sighandler and call pthread_exit() and continue on with the program. But not every segfault is going to be the result of a bad rwe. I need to find a way to use the siginfo type to determine if the segfault was bad programming or this error. Any

OpenCl cleanup causes segfault

二次信任 提交于 2020-01-04 02:04:06
问题 I constructed my own little Opencl example using different sources on the net. The actual kernel works, and I get the output I want, but the cleanup functions, I found in one of the examples, cause segfaults. What did I do wrong? #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <CL/cl.h> //opencl #define CL_CHECK(_expr) \ do { \ cl_int _err = _expr; \ if (_err == CL_SUCCESS) \ break; \ fprintf(stderr, "OpenCL Error: '%s' returned %d!\n", #_expr, (int)_err); \ abort(); \ }

C: Segmentation fault: GDB: <error reading variable>

孤人 提交于 2020-01-04 01:36:12
问题 I have a function shortestPath() that is a modified implementation of Dijkstra's algorithm for use with a board game AI I am working on for my comp2 class. I have trawled through the website and using gdb and valgrind I know exactly where the segfault happens (actually knew that a few hours ago), but can't figure out what undefined behaviour or logic error is causing the problem. The function in which the problem occurs is called around 10x and works as expected until it segfaults with GDB:

Why would one crash log symbolicate and not another?

半腔热情 提交于 2020-01-03 17:01:05
问题 I have two crash logs from a iPhone application in XCode Organizer. Both occurred within 20 minutes of each other, on the same device, running the same build of the application. While one has been symbolicated the other has not. The unsymbolicated log has type and codes: Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x00000000, 0x00000000 Whereas the symbolicated log has type and codes: Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x61656810 Is this