segmentation-fault

Segmentation fault in strtok

杀马特。学长 韩版系。学妹 提交于 2019-12-23 23:52:01
问题 I keep getting that error. I am pretty sure it has something to do with memory allocation but i'm not quite sure how to fix it. #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <string.h> char * VOWELS ="aeiouAEIOU"; void printLatinWord(char *a); int main(int argc, char **argv){ char phrase[100]; char *word = malloc(sizeof(char) *100); printf("Enter the phrase to be translated: \n"); fgets(word, 100, stdin); printf("The phrase in Pig Latin is:\n"); word = strtok(phrase, " "

pointer to one struct in another, writing and reading it from file gives SegFault

左心房为你撑大大i 提交于 2019-12-23 19:40:32
问题 I am brushing up my C skills from Learn C The Hard Way, currently I am at 17th Exercise. I am doing the 'Extra Credits' part. Making the database code given on that page to get I am trying to "Change the code to accept parameters for MAX_DATA and MAX_ROWS, store them in the Database struct, and write that to the file, thus creating a database that can be arbitrarily sized" So, I commented out the #define directives, and changed Address and Database structs as given: struct Address { int id;

2D vector giving segmentation fault

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 19:29:43
问题 I am trying to create a 2D array using vector. I have written the following code: int main() { vector< vector<int> > v; int i, j; for(i=0; i<11; i++) for(j=0; j<11; j++) v[i].push_back(j); for(i=0; i<11; i++) { for(j=0; j<11; j++) cout<<v[i][j]<<" "; cout<<endl; } return 0; } Now I was expecting it to print the numbers 0 to 10, eleven times (each time in a new line). But the code is giving runtime error (segmentation fault). Can anybody please tell me where I am going wrong? Thanks. 回答1: When

MongoDB C++ Segmentation Fault

两盒软妹~` 提交于 2019-12-23 14:03:21
问题 The Problem I am trying to connect to MongoDB in C++. The following code does actually compile. However, when I try to run the program, I get a segmentation fault. - Edit - This is what I get after running it in gdb (no change in source code or makefile): GDB Run: Starting program: /home/nathanw/devel/Linux/mkfarina-cpp/mkfarina [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff69ae700 (LWP 13314)]

c++ STL map::operator[] done on an entry being deleted

£可爱£侵袭症+ 提交于 2019-12-23 13:07:24
问题 std::map<int,int> bar; int foo(int key) { bar.erase(key); return 1; } int main() { bar[0] = foo(0); return 0; } This code compiled with GCC 4.8 segs fault when checking memory usage with electric fence. LD_PRELOAD=libefence.so.0.0 ./a.out The problem comes from the fact that the compiler generates a code that starts to allocate a new entry in the map, then executes foo() to get the value to put into bar[0] . While running foo() , the entry gets destroyed and the code finally ends by writing

python libsvm core dump

╄→尐↘猪︶ㄣ 提交于 2019-12-23 12:54:15
问题 I have Python code that works fine on my development environment (Ubuntu 12.04) but dumps core on my production environment (a Linode running CentOS). *** glibc detected *** python2.7: double free or corruption (out): 0x090cba60 *** ======= Backtrace: ========= /lib/i686/nosegneg/libc.so.6(+0x717b1)[0xb763d7b1] /lib/i686/nosegneg/libc.so.6(+0x73f01)[0xb763ff01] /home/michael/libsvm-3.16/python/../libsvm.so.2(svm_free_model_content+0xe2)[0xb6e0c6b2] /home/michael/libsvm-3.16/python/../libsvm

Segmentation fault: 11 - Cross-reference to module

微笑、不失礼 提交于 2019-12-23 10:19:56
问题 I'm trying to resolve an Segmentation Fault with Cross-references to modules. Don't know how to make this work. Part of error below: 1. While reading from /Users/damiandudycz/Library/Developer/Xcode/DerivedData/Hypno-azmcjycezcoqnfauqcbgimvipjyj/Build/Intermediates/Hypno.build/Debug-iphonesimulator/Hypno.build/Objects-normal/x86_64/WorldObjectBasedAugmentedRealityObject~partial.swiftmodule 2. While deserializing 'WorldObjectBasedAugmentedRealityObject' (ClassDecl #12) 3. While deserializing

C++ SegFault when dereferencing a pointer for cout

徘徊边缘 提交于 2019-12-23 10:09:43
问题 I'm new to C++ and just trying to get a hang of it. It generally seems not too bad, but I stumbled upon this weird/pathological segfaulting behavior: int main () { int* b; *b = 27; int c = *b; cout << "c points to " << c << endl; //OK printf( "b points to %d\n", *b); //OK // cout << "b points to " << (*b) << endl; - Not OK: segfaults! return 0; } This program, as given, produces what you'd expect: c points to 27 b points to 27 On the other hand, if you uncomment the second-to-last line, you

Boost test crashes on exit with Clang 4.1 (LLVM 3.1svn)

你。 提交于 2019-12-23 07:31:18
问题 Consider this simple program: #include <string> #include <iostream> #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "MyTest" #include <boost/test/unit_test.hpp> using namespace std; template<char* S> void Test() { BOOST_REQUIRE("Boom!" != string(S)); } char bang[] = "Bang!"; BOOST_AUTO_TEST_CASE(Boom) { char boom[] = "Boom!"; Test<bang>(); } I'm on Mac OS X v10.8.2 (Mountain Lion) and have XCode 4.5 installed. The program works when compiled with GCC, for example, gcc test.cpp -lboost

Boost test crashes on exit with Clang 4.1 (LLVM 3.1svn)

若如初见. 提交于 2019-12-23 07:31:09
问题 Consider this simple program: #include <string> #include <iostream> #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "MyTest" #include <boost/test/unit_test.hpp> using namespace std; template<char* S> void Test() { BOOST_REQUIRE("Boom!" != string(S)); } char bang[] = "Bang!"; BOOST_AUTO_TEST_CASE(Boom) { char boom[] = "Boom!"; Test<bang>(); } I'm on Mac OS X v10.8.2 (Mountain Lion) and have XCode 4.5 installed. The program works when compiled with GCC, for example, gcc test.cpp -lboost