segmentation-fault

Object created in for-loop has same address

孤人 提交于 2019-12-11 00:59:05
问题 I'm trying to make an own list-class which is of a fixed size and can store integers. Just for learning purposes. This is how I do it: I have a struct called Item which holds the data (the integer to store), and a pointer to the next item in the list. When the list gets initialized I first add x amount of empty Items to the list. The address of item declared in iteration (n-1) is stored in a buffer, so that the address of the item in iteration n, can be set as next for the item in the

Segmentation fault in a function to reverse a singly linked list recursivley

怎甘沉沦 提交于 2019-12-11 00:49:43
问题 I am implementing a function to recursively reverse a linked-list, but getting seg-fault. typedef struct _node { int data; struct _node *next; } Node, *NodeP; NodeP recursiveReverseList(NodeP first){ if(first == NULL) return NULL; if(first->next == NULL) return first; NodeP rest = recursiveReverseList(first->next); rest->next = first; first->next = NULL; return first; } Can you please help? P.S. The iterative version is working fine though. Its not homework. Just practicing C. Thank you all :

nested std::forward_as_tuple and segmentation fault

浪子不回头ぞ 提交于 2019-12-11 00:29:35
问题 My actual problem is a lot more complicated and it seems extremely difficult to give a short concrete example here to reproduce it. So I am posting here a different small example that may be relevant, and its discussion may help in the actual problem as well: // A: works fine (prints '2') cout << std::get <0>(std::get <1>( std::forward_as_tuple(3, std::forward_as_tuple(2, 0))) ) << endl; // B: fine in Clang, segmentation fault in GCC with -Os auto x = std::forward_as_tuple(3, std::forward_as

Why doesn't this program segfault?

烈酒焚心 提交于 2019-12-11 00:19:37
问题 What causes the output "Hello" when I enable -O for gcc ? Shouldn't it still segfault (according to this wiki) ? % cat segv.c #include <stdio.h> int main() { char * s = "Hello"; s[0] = 'Y'; puts(s); return 0; } % gcc segv.c && ./a.out zsh: segmentation fault ./a.out % gcc -O segv.c && ./a.out Hello 回答1: It's undefined behavior (might crash, might not do anything , etc) to change string literals. Well explained in a C FAQ. 6.4.5/6 It is unspecified whether these arrays are distinct provided

segfault with unixODBC (DB2) + PHP + CentOS

余生长醉 提交于 2019-12-11 00:08:56
问题 After 2 days battling, I try asking help here. I'm using unixODBC (2.2.11) to work with DB2 (iSeries) and PHP (5.3) on a CentOS 5.4 server. I guess it's since the upgrade of PHP from 5.1 to 5.3, I get PHP to segfault on certain queries. After some investigation, I discovered the problem appears on some queries with long char fields, for example with this table : TABLE ( CONTRACTID NUMERIC, SOMETEXT CHAR(583) ) This simple piece of code provokes the segfault : try { $conn = new PDO("odbc:".

iPhone SIGSEGV crash with any level of Optimization using ARC+ASIHTTPRequest

China☆狼群 提交于 2019-12-10 23:57:35
问题 I currently use ASIHTTPRequest for synchronous requests I recently refactored my code to comply with ARC and omit the ASIHTTPRequest class using the compiler flag -fno-objc-arc I have a _mh_execute_header SIGSEGV crash when I use any type of optimization While turning off all optimization allows my app to run - I need to be able to optimize the app using the iOS default settings which use Fastest, Smallest [-Os] Since this is a memory related issue and since the only manually managed memory

Segmentation fault when accessing a list inside a struct

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 23:32:53
问题 I'll try to make things clear. Here is my struct: struct scopeList{ int id; list<int> internal_list; }; typedef struct scopeList scopeList_T; Here is the code that gives me the segmentation. int main(){ scopeList_T* t1 = (scopeList_T*) malloc(sizeof(scopeList_T)); t1->id = 5; //works fine t1->internal_list.push_front(5); //segmentation fault } Since I am allocating memory and accessing id is fine, why is does this give me a segmentation fault? Do I have to do something special to the list

A thread-safe vector and string container?

拈花ヽ惹草 提交于 2019-12-10 23:24:54
问题 I posted a previous question "Seg Fault when using std::string on an embedded Linux platform" where I got some very useful advise. I have been away on other projects since then and have recently returned to looking at this issue. To reiterate, I am restricted to using the arm-linux cross compiler (version 2.95.2) as this is what is supplied and supported by the embedded platform vendor. I understand that the issue is likely because the stdlib is very old, and not particularly thread safe. The

Why am I getting a segmentation fault from scanf loop?

微笑、不失礼 提交于 2019-12-10 23:22:12
问题 The segmentation fault error disappears after commenting out the scanf loop. Why is that loop giving me a segmentation fault? char** nameArray = malloc(numNames * sizeof(char *)); for(i =0; i< 10; i++) { nameArray[i] = malloc(25 * sizeof(char)); } for (i = 0; i< numNames; i++) { scanf("%s", &nameArray[i]); } for (i =0; i<numNames; i++) { free(nameArray[i]); } 回答1: First you need to change for(i =0; i< 10; i++) { to for(i =0; i< numNames; i++) { as you need to create enough entries. Also you

Segmentation Fault when deploying to handset

点点圈 提交于 2019-12-10 23:14:59
问题 I've got a Galaxy Nexus and today it started to give me a Segmentation fault error when deploying to it: [2011-12-07 16:19:17 - Flinders Lite] Android Launch! [2011-12-07 16:19:17 - Flinders Lite] adb is running normally. [2011-12-07 16:19:17 - Flinders Lite] Performing com.istudentgroup.flinders.lite.activity.MainMenuActivity activity launch [2011-12-07 16:19:20 - Flinders Lite] Uploading Flinders Lite.apk onto device '0146914B19021011' [2011-12-07 16:19:23 - Flinders Lite] Installing