segmentation-fault

seg fault caused by malloc and sscanf in a function

不想你离开。 提交于 2019-12-11 09:04:54
问题 I want to open a text file (see below), read the first int in every line and store it in an array, but I get an segmentation fault. I got rid of all gcc warnings, I read through several tutorials I found on the net and searched stackoverflow for solutions, but I could't make out, what I am doing wrong. It works when I have everything in the main function (see example 1), but not when I transfer it to second function (see example 2 further down). In example 2 I get, when I interpret gdb

RSA mpz_powm() in for-loop: seg fault

你离开我真会死。 提交于 2019-12-11 09:01:45
问题 This is a follow-up question to a previous question (now that the actual issue is different): int main() { mpz_t p, q, n, phi_n, e, d; mpz_inits(p, q, n, phi_n, e, d, NULL); generate_pq(p,q); compute_n(n,p,q); compute_phiN(phi_n,p,q); mpz_clear(p,q,NULL); select_e(e,phi_n); compute_d(d,e,phi_n); mpz_clear(phi_n); mpz_t* m; int size=0; store_m(m,size); mpz_t* c; encrypt(c,m,size,e,n); return 0; } Here are the relevant functions: void store_m(mpz_t m[], int& size) { /* m = original message */

How to avoid SIGSEGV?

孤街浪徒 提交于 2019-12-11 09:00:47
问题 I am writing a client-server daemon which have to accept and translate specific message formats, check them submit to submit all activity to DB. Program is multithreaded. So, I started to work, and began to get SIGSEGV in some cases. So I had to redesign my program and start all over. I am wondering, if there are any "best practices" or tips on how to minimize risk of SIGSEGV ? I know, that each pointer should be checked before usage and NULLED after deleting, but if there any high level,

What actually happens when calling a getter function for an instance variable(that is an object)?

爱⌒轻易说出口 提交于 2019-12-11 08:58:44
问题 Lately I have had a constant battle with a function causing a SEGFAULT randomly. After doing some extra work in trying to find out the problem, I have come up with the following: All code posted via pastebin: BUILD 1:This is the original code, it causes the following SEGFAULT (given after link) http://pastebin.com/huzcqnDA SEGFAULT: #0 6FC657AC libstdc++-6!_ZNKSs4_Rep12_M_is_leakedEv() (Z:\CPP Programming\CodeBlocks\MinGW\bin\libstdc++-6.dll:??) #1 6FC89FDB libstdc++-6!_ZNSs4_Rep7_M

Android Java App Crashing with SIGSEGV

一笑奈何 提交于 2019-12-11 08:51:04
问题 My android application sometimes crashes without any error message. The app just closes up and the device returns to the home screen. Normally there would be some error message that the app crashed but nothing shows up. Logcat shows that some kind of segmentation violation happened causing the crash but as the app only consists of java code and no native code I'm really curious why the app is crashing.Can anybody give me a clue? Here is what logcat is showing when the app is crashing: D

Why do I get a segmentation fault when I am trying to insert into a tree*

半腔热情 提交于 2019-12-11 08:32:07
问题 #include<iostream> #include<set> #include<stdlib.h> using namespace std; typedef set<short> pos; typedef struct tree { pos first; }tree; class check { public: pos last; void check_set(); }; void check::check_set() { tree *root,p; root=(tree*)malloc(sizeof(tree)); root->first.insert(2);//SEGMENTATION FAULT HERE WHY??? p.first.insert(3);//NO SEGMENTATION FAULT } int main() { check obj; obj.check_set(); obj.last.insert(1);//NO ERROR HERE return 0; } 回答1: Use new instead of malloc . malloc only

Seg fault when saving data using boost::serialization

我只是一个虾纸丫 提交于 2019-12-11 08:16:57
问题 When trying to save the database using boost serialization, I encounter the segfault that I could not resolve. Would you please help? Any suggestion is greately appreciated. I've pinned down the statement below as the culprit but not sure of how to resolve it oa << *this; My code section is below: template<class Archive> void nDB::serialize(Archive &ar, const unsigned int version) { ar & _LAYERS; ar & _MACROS; ar & _MODULES; ar & _INSTS; } void nDB::save_db(string filename) { std::ofstream

sdl2 SDL_Quit() segmentation fault

我是研究僧i 提交于 2019-12-11 08:15:37
问题 I encounter a segmentation fault when calling SDL_Quit() with the following code: #include <SDL2/SDL.h> #include <stdio.h> const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; int init(){ return SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); } void close(){ SDL_Quit(); return; } int main(int argc, char *argv[]) { if( init() < 0 ){ SDL_Log("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_Delay(1000); close(); return 0; } This is the gdb output: Breakpoint 1, main (argc=1,

Segmentation fault while using MPI_Barrier in `libpmpi.12.dylib`

北战南征 提交于 2019-12-11 08:08:02
问题 I install mpich using brew install mpich , but if I use MPI_Barrier , I will get segmentation fault. See the simple code below: // A.c #include "mpi.h" #include <stdio.h> int main(int argc, char *argv[]) { int rank, nprocs; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Barrier(MPI_COMM_WORLD); printf("Hello, world. I am %d of %d\n", rank, nprocs);fflush(stdout); MPI_Finalize(); return 0; } mpicc A.c -g -O0 -o A After running mpirun -n 2

How do I get a core dump on OS X Lion?

拥有回忆 提交于 2019-12-11 07:59:58
问题 I am working on a PostgreSQL extension in C that segfaults, so I want to look at the core dump file on my OS X Lion box. However, there are no core files in /cores or anywhere else that I can find. It appears that they are enabled in the system but are limited to a size of 0: > sysctl kern.coredump kern.coredump: 1 > ulimit -c 0 I tried setting ulimit -c unlimited in the shell session I'm using to start and stop PostgreSQL, and it seems to stick: > ulimit -c unlimited And yet no matter what I