segmentation-fault

C++: Why does dereferencing this vector iterator segfault?

只愿长相守 提交于 2019-12-13 16:24:15
问题 void insert_string( std::vector<std::string> & strings, const std::string &s ) { std::vector<std::string>::iterator it=lower_bound(strings.begin(),strings.end(),s); if(strings.size()>0) std::cout<<*it<<" is found\n"; // **** strings.insert(it,s); } When attempting to use this function, the first insertion goes fine. The second insertion will output "[firststring] is found" and then segfault. If I comment out the if/cout line, I can repeatedly call and no segfaults occur. I've also tried doing

Segmentation Fault while deferencing a char array

走远了吗. 提交于 2019-12-13 16:17:20
问题 #include<stdio.h> int main(void) { char * p= "strings are good"; printf("%s",*p); return 0; } Could somebody please tell me why I am getting segmentation fault here? 回答1: Could somebody please tell me why I am getting segmentation fault here? C11: 7.21.6 Formatted input/output functions: If a conversion specification is invalid, the behavior is undefined.282) If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined. 3.4.3 1 undefined

Boost Fusion container of shared pointers (shared_ptr) causing Segmentation Fault (sigsegv) or garbage results

微笑、不失礼 提交于 2019-12-13 16:16:00
问题 Edit: This turned out to be an issue with temporaries. Basically, I was ignorantly using C++ as if it worked like Java or C#, which it does not. Hopefully, this will be a good cautionary tale. Edit: This issue only seems to happen with the combination of joint_view and shared_ptr . Raw pointers seem to work fine in the same scenario, as do shared pointers in a plain fusion container constructed w/ all its items at once, without adding anything more to it. Details below: I'm using mingw gcc 4

Why the SIGSEGV?

最后都变了- 提交于 2019-12-13 14:27:03
问题 Why is this code throwing up a SIGSEGV: int main() { unsigned long toshuffle[9765625]; unsigned long i; for (i=0; i< 1000; i++) toshuffle[i]= i; return 0; } Pointers will be appreciated. (No Pun intended :)) 回答1: Use malloc() to get that much memory. You're overflowing the stack. unsigned long *toshuffle = malloc(9765625 * sizeof(unsigned long)); Of course when you're done with it, you'll need to free() it. NOTE: In C++, you need to cast the pointer to the correct type. 回答2: Probably because

unable to execute command: Segmentation fault: 11 swift frontend command failed due to signal (use -v to see invocation)

做~自己de王妃 提交于 2019-12-13 12:52:36
问题 I have an iOS swift program that compiles and runs fine on Xcode Beta2. When I downloaded beta4, I got a few syntax errors for the new swift language which I corrected. I now get this error: <unknown>:0: error: unable to execute command: Segmentation fault: 11 <unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation) The problem is that it does not tell me where this error is so that I can further troubleshoot it. Where can I type -v in order to "see the

strcpy()/strncpy() crashes on structure member with extra space when optimization is turned on on Unix?

纵饮孤独 提交于 2019-12-13 11:36:27
问题 When writing a project, I ran into a strange issue. This is the minimal code I managed to write to recreate the issue. I am intentionally storing an actual string in the place of something else, with enough space allocated. // #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <stddef.h> // For offsetof() typedef struct _pack{ // The type of `c` doesn't matter as long as it's inside of a struct. int64_t c; } pack; int main(){ pack *p; char str[9] =

Segmentation fault - Two functions don't run simultaneously

落爺英雄遲暮 提交于 2019-12-13 10:48:31
问题 I have the following code for my program int main(void) { int i,size; float vel_x[size],vel_y[size],vel_x0[size],vel_y0[size],rho[size],rho0[size]; float *ux, *vy, *ux0, *vy0; float *r, *r0; struct fdparam fdparam_1; printf("Enter the number of grid points: \t"); scanf("%d", &fdparam_1.N); printf("Enter the maximum number of iterations: \t"); scanf("%d", &fdparam_1.MAXIT); printf("Enter the value for time domain: \t"); scanf("%f", &fdparam_1.t_domain); printf("Enter the time step and density

Program received signal SIGSEGV, segmentation fault, Linked list program

戏子无情 提交于 2019-12-13 09:37:45
问题 #include <stdio.h> #include <stdlib.h> typedef struct node{ int value; struct node* next; }Node; Node* createNode(int data); Node* insertFront(Node* first, Node* newNode); void printList(Node* first); void deleteList(Node* first); int main(int argc, const char **argv) { int numItems, ch; FILE *fp; fp = fopen(argv[1], "r"); while ((ch = getc(fp)) != EOF) { if (ch = '\n') numItems++; } fclose(fp); Node *first = NULL; Node *newNode; Node *Next; int i; for(i = 1; i <= numItems; i++) { newNode =

Segmentation fault after using dynamic bitset in C++

狂风中的少年 提交于 2019-12-13 08:49:03
问题 I am trying to make a variable length linear feedback shift register, so I used dynamic bitset instead from boost library instead of bitset. After compiling the program, and when running it, it produced Segmentation fault directly after it shows the contents of xorArray. I think the mistake is in the definition of the dynamic bitset variables, but I can't figure it out. There are three variables, inpSeq, operSeq and bit. Here is the code: #include <iostream> //Standard library. #include

Weird Segmentation Fault after printing

纵饮孤独 提交于 2019-12-13 08:24:57
问题 Wrote a simple swap program, works well; But gives a Segmentation Fault after printing everything. #include <stdio.h> void swap(int* p1,int* p2){ int* temp; *temp = *p1; *p1 = *p2; *p2 = *temp; } int main(){ int a,b; a = 9; b = 8; printf("%d %d \n",a,b); swap(&a,&b); printf("%d %d \n",a,b); return 0; } Output: 9 8 8 9 Segmentation fault Should I simply ignore this and move forward or is there something really strange going on ? 回答1: int* temp; *temp = *p1; is undefined behaviour in C and C++