segmentation-fault

Segmentation fault in C with malloc

老子叫甜甜 提交于 2019-12-13 04:46:29
问题 I'm getting a segmentation fault for the below scenario: When reading from a file for a list of ip addresses, i store the IP ADDRESS and port in a link list. As my while loops for file reading repeats itself, as per link list logic - when i malloc my temp pointer again i face segmentation fault. Please find below the code snippet: struct woker_conf { int port; char *ip_address; struct worker_conf *next; } *head; void open(int8_t nbrwrk) { FILE *fp = NULL; char line[1024] = {0}; int i = 1;

Pthreads matrix multiplication error

岁酱吖の 提交于 2019-12-13 04:29:25
问题 I want to use pthreads on my existing serial matrix multiplication code. My goal is to achieve better execution time using pthreads, simply to achieve speed-up. But at that point I'm stuck. My original serial code, works just fine, and I finish 1000x1000 square matrix multiplication in about 15 seconds. But when I execute my current pthreads program, I get a segmentation fault. Here is my code: #include <stdio.h> #include <stdlib.h> #include <time.h> #include <assert.h> int SIZE, NTHREADS;

Is there any way to keep a memory block for a container?

我们两清 提交于 2019-12-13 04:02:08
问题 I hope I'll be clear.... In my code, I define a box which holds a set of elements ( bead ): vector<vector<vector<set<std::tr1::shared_ptr<bead> > > > > boxes; I am adding element to the box using: boxes[i][j][k].insert(aBead); For some reason I get a segmentation fault here. As far as I can tell, The segmentation fault does not occur because of illegal bead and i , j , k , are all smaller than the box's size and are not negative. In case you wonder bead is: class particle{ public: vec pos;

Cannot figure out Seg Fault, lots of detail provided

。_饼干妹妹 提交于 2019-12-13 03:55:56
问题 I asked this question about a half hour ago, but the code had typos and I wasn't being very clear, so I've deleted and I'm trying again with a better format. I'm getting a Segmentation Fault in my code, the problem seems to be at the function call if( (*trans).test((*this), *(*itr)) ) inside World::update() : void World::update(sf::Time dt) { mPlayer->setVelocity(0.f, 0.f); while (!mCommandQueue.isEmpty()){ Command cmd = mCommandQueue.pop(); cmd.action(cmd.node, dt); } mSceneGraph.update(dt);

Eigenvalue calculation using TQLI algorithm fails with segmentation fault

丶灬走出姿态 提交于 2019-12-13 03:50:35
问题 I am trying to calculate eigenvalues using the TQLI algorithm that I got from the website of the CACS of the University of Southern California. My test script looks like this: #include <stdio.h> int main() { int i; i = rand(); printf("My random number: %d\n", i); float d[4] = { {1, 2, 3, 4} }; float e[4] = { {0, 0, 0, 0} }; float z[4][4] = { {1.0, 0.0, 0.0, 0.0} , {0.0, 1.0, 0.0, 0.0} , {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0} }; double *zptr; zptr = &z[0][0]; printf("Element [2][1] of

Segmentation fault with std::uniform_int_distribution

元气小坏坏 提交于 2019-12-13 03:46:15
问题 EDIT EDIT: A minimal reproducible example worked fine, in the end, I resolved the problem by carefully rebuilding my program. Doing so, I found a wrong access of an std::vector, which was probably one of the reasons execution failed. So, long story short: I meessed up my code and didn't look carefully enough before posting this question. However, as pointed out in the comments, I should not access uninitialized pointers as I am doing in my snippet below ( RNG* r ) even if they're static.

segmentation fault at __tcf_0 when program exits

一笑奈何 提交于 2019-12-13 03:33:37
问题 when program exits, the information is given: *** glibc detected *** double free or corruption (!prev): 0x09a8fcb8 *** It seems like double free at one object. Then I used gdb to debug the coredump file. The following is the bt result(more traces are not posted): #0 0x005197a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 #1 0x0055a825 in raise () from /lib/tls/libc.so.6 #2 0x0055c289 in abort () from /lib/tls/libc.so.6 #3 0x0058ecda in __libc_message () from /lib/tls/libc.so.6 #4

What is the proper way to call default constructors?

血红的双手。 提交于 2019-12-13 02:57:17
问题 Lately I have been having difficulties with constructors, and the different attempts from other questions and guides always have some form of segfault waiting for me at runtime (making compiling 80% of my time spent programming). The following example shows the basic idea on what I am trying to accomplish: struct Coord3{ float x, y, z; Coord3() {x=0;y=0;z=0;};///Is this Correct? }; struct Stat{ int Str,Dex,Int; Stat(){Str=0;Dex=0;Int=0;}; }; struct Item{ Stat myStats; Item(){...}; }; class

How can I fix this Segmentation fault using SFML?

与世无争的帅哥 提交于 2019-12-13 02:32:42
问题 I am having a segmentation fault error when running this code The error is triggered at the draw function of the custom object. I believe that its related to the address of the window. GameObject *obj = new Dummy; //game loop while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); obj->draw(window); window.display(); } return 0; } I pasted the whole code here 回答1: I fixed it. The problem was that I was

When is the segfault thrown?

♀尐吖头ヾ 提交于 2019-12-13 02:22:48
问题 Suppose I have a class like class A { int x; int y; public: getSum1() const { return getx() + y; } getSum2() const { return y + getx(); } getx() const { return x; } } And then I have int main(int argc, char **argv) { A *a = 0; switch(argc) { case 0: a->getsum1(); break; default: a->getsum2(); break; } return 1; } This program will segfault. I noticed that on my machine, when getsum1 executes, the core dump says the segfault was caused in getx, and when getsum2 executes it says the fault