segmentation-fault

Problem allocating derived class array with new

烂漫一生 提交于 2019-12-08 09:19:16
问题 I have a simple program $ cat a.cpp #include <iostream> class MyClass { public: virtual void check() { std::cout << "Inside MyClass\n"; } }; class MyClass2: public MyClass { public: int* a; virtual void check() { std::cout << "Inside MyClass2\n"; } }; int main() { MyClass *w, *v; w = new MyClass2[2]; v = new MyClass2; std::cout << "Calling w[0].check\n"; w[0].check(); std::cout << "Calling v->check\n"; v->check(); std::cout << "Calling w[1].check\n"; w[1].check(); } $ g++ a.cpp $ ./a.out

Segmentation fault for pthreads in a recursive call

老子叫甜甜 提交于 2019-12-08 08:50:41
问题 Given the code below, I get a segmentation fault if I run it with n>16. I think it has something to do with the stack, but I can't figure it out. Could anyone give me a hand? The code is not mine, and really not important. I would just like someone to give me a hand with what is happening. This SO question is very similar, but there's not enough information (the person who posts the answer briefly talks about the problem, but then goes on to talk about a different language). Besides, notice

Very strange segfault calling WinUsb_GetOverlappedResult

倾然丶 夕夏残阳落幕 提交于 2019-12-08 08:17:42
问题 I have this code: void GetResult(WINUSB_INTERFACE_HANDLE InterfaceHandle, LPOVERLAPPED lpOverlapped) { DWORD numBytes = 0; WinUsb_GetOverlappedResult( InterfaceHandle, lpOverlapped, &numBytes, TRUE ); return; uint8_t stack[64]; } WinUsb_GetOverlappedResult is a __stdcall function declared as follows: WINBOOL WINAPI WinUsb_GetOverlappedResult (WINUSB_INTERFACE_HANDLE InterfaceHandle, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, WINBOOL bWait); Compiling in debug mode with GCC

pthread_create causing segmentation fault

女生的网名这么多〃 提交于 2019-12-08 08:10:09
问题 My program contains the following code. pthread_t PThreadTable[32]; for (i=1; i<P; i++) // Checked with P = 4 { long i, Error; printf( "pthread_create %d!\n", i ); Error = pthread_create(&PThreadTable[i], NULL, (void * (*)(void *))(SlaveStart), NULL); if (Error != 0) { printf("Error in pthread_create().\n"); exit(-1); } } SlaveStart(); The code gives segmentation fault on calling pthread_create (checked through gdb and valgrind ). Why so? 回答1: Its because you redeclare variable i inside the

TOUGH: Dealing with deeply nested pointers in C++

点点圈 提交于 2019-12-08 08:09:44
问题 I define this structure: struct s_molecule { std::string res_name; std::vector<t_particle> my_particles; std::vector<t_bond> my_bonds; std::vector<t_angle> my_angles; std::vector<t_dihedral> my_dihedrals; s_molecule& operator=(const s_molecule &to_assign) { res_name = to_assign.res_name; my_particles = to_assign.my_particles; my_bonds = to_assign.my_bonds; my_angles = to_assign.my_angles; my_dihedrals = to_assign.my_dihedrals; return *this; } }; and these structures: typedef struct s_particle

Segfault in SIGSEGV handler

自古美人都是妖i 提交于 2019-12-08 08:00:08
问题 Lets assume I have the following C code: static void handler(int sig, siginfo_t *si, void *unused) { printf("BOOM!\n"); //another segfault here exit(-1); } int main(int argc, char *argv[]) { struct sigaction sa; sa.sa_flags = SA_SIGINFO; sigemptyset(&sa.sa_mask); sa.sa_sigaction = handler; if (sigaction(SIGSEGV, &sa, NULL) == -1) perror("failed to set handler"); // call other stuff here, somewhere in the callstack a segfault happens } If the execution hits the first segmentation fault the

Android SIGSEGV error when recording audio

孤街醉人 提交于 2019-12-08 07:31:13
问题 I need your help. I'm trying to record some audio with Androids AudioRecord class. Most time this works very well but sometimes I get a SIGSEGV error. Here is the code which runs in a seperate Thread while recording audio: private void startRecording() { recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bufferSize); recorder.startRecording(); isRecording = true; recordingThread = new Thread(new Runnable() { @Override

Django South Seg Fault

ε祈祈猫儿з 提交于 2019-12-08 07:01:00
问题 I just updated from Ubuntu 12.04 to 13.04, and I am having issues migrating some code that used to work. Googling does not reveal anything that obviously looks related except some obscure R references, and though my project does use R I would not expect it to crop up in migrations. I have never dealt with debugging seg faults before, much less in 3rd party code. How should I proceed? (project)ben@Watt:~/Projects/project/project$ python project/manage.py migrate Error: 'rho' must be an

Dynamic Allocation of 2D Array

血红的双手。 提交于 2019-12-08 05:14:14
问题 I am implementing graphs using adjacency matrix, but I am unable to solve the segmentation fault. Can anyone help me in guiding dynamic allocation of two dimensional matrix? I also want to know how is 2-D array stored in memory and how it is accessed. #include<stdio.h> #include<stdlib.h> struct Graph{ int V; // To represent number the vertex... int E; //To represent number the Edge..... int **Adj; // Two dimensional matrix to form the adjacency matrix... }; struct Graph *adjMatrixOfGraph(){

Invisiable SIGSEGV on linux that does not happen on windows?

 ̄綄美尐妖づ 提交于 2019-12-08 04:55:33
问题 INTRO I have a TCP/HTTP server that supports plugins in form of Shared Libraries ( DLL and .so ). It has make and .sln files build system via premake. When I start my application I feed to it a configuration file like this with description of what libraries server shall use as plugins and what arguments it shall pass to tham. For some time I had 2 plugins and all worked just fine. and even now works just fine if I feed to my server config fdiles alike this. But Now I have new plugin I am