segmentation-fault

Segmentation fault with queue in C

I am getting a segmentation fault with the following code after adding structs to my queue. The segmentation fault occurs when the MAX_QUEUE is set high but when I set it low (100 or 200), the error doesn't occur. It has been a while since I last programmed in C, so any help is appreciated. #include <stdio.h> #include <stdlib.h> #incl...

C: sprintf and recursion

In C, is it possible to use recursion within the sprintf function ? For some reason I get a segmentation fault when I do it: inline char *TreeNode_toString(const TreeNode *node) { char *out; if(TreeNode_isExternal(node)) // If the node has no children... { sprintf(out, "%s:%.2f", node->name, node->distance); } else // The...

How the kernel gives seg. fault for a scenario like this?

I have a doubt in accessing some invalid data. How can the OS cause a segmentation fault for a scenario like this: Suppose a chunk of data is 100 bytes long, aligned at the beginning of a 4K page. If we access the valid data within the first 100 bytes of the page, this will load the page into memory, and put the page table entry is in T...

How do I know which illegal address the program access when a segmentation fault happens

Plus, The program runs on a arm device running Linux, I can print out stack info and register values in the sig-seg handler I assign. The problem is I can't add -g option to the source file, since the bug may won't reproduce due to performance downgrade. ...

Getting "Segmentation fault: 11" with imap extention

Hello everyone, This is something that irritate me from some time - I am using php imap extension to connect to email box and retrieve emails. Before with php version 5.2.9 all worked well , but had to upgrade to 5.2.13 because the production server running this version. Then it start crashing with "Segmentation fault: 11" on imap_fetch...

Why does this program segfault

Upon compiling and running this small program to reverse a string, I get a Segmentation Fault before any output occurs. Forgive me if this is an obvious question, I'm still very new to C. #include <stdio.h> int reverse(char string[], int length); int main() { char string[] = "reversed"; printf("String at start of main = %s", stri...

Segmentation fault problem (C)

I have a struct named Game with an array of levels, defined like this: typedef struct { Level levels[x]; } Game; When I compile the code, if x is 1, 2 or 3, the program runs normally. If it's any other value (4, for instance), I get a segmentation fault. I'm not accessing the array anywhere. Main is something like this at the mo...

PHP Segmentation fault when started from crond

Hello, I've a php script that's started each minute from cron. It almost always runs without any problem, except for about 10 times within 24h. The times it fails I get a segmentation fault like: bin/sh: line 1: 21815 Segmentation fault /usr/bin/myscript The number after "line 1:" is always different. I'm running: PHP 5.2.6-1+l...

Why is this RMagick call generating a segmentation fault?

I've been banging my head against the wall for the better part of an hour trying to figure out what's going wrong here, and I'm sure (or rather hoping) it's something fairly obvious that I'm overlooking. I'm using Ruby 1.9.1, Sinatra 1.0, and RMagick 2.13.1. ImageMagick and RMagick are correctly installed and functional—I've successfully...

Seg Fault with malloc'd pointers

I'm making a thread class to use as a wrapper for pthreads. I have a Queue class to use as a queue, but I'm having trouble with it. It seems to allocate and fill the queue struct fine, but when I try to get the data from it, it Seg. faults. http://pastebin.com/Bquqzxt0 (the printf's are for debugging, both throw seg faults) edit: the q...

qapps runs well but breakpoint sometimes generates segmentation fault

I have a qApp that generates a segmentation fault only when a breakpoint is inserted in the code (I can put it at different places) and only after 4-5 breakpoint stops. Do I have a problem with my code or is this a DBG bug. the method is part of a QThread Class. Basically what I did is i took the mandlebrot example, and have 3 instan...

Help with infrequent segmentation fault in accessing boost::unordered_multimap or struct

I'm having trouble debugging a segmentation fault. I'd appreciate tips on how to go about narrowing in on the problem. The error appears when an iterator tries to access an element of a struct Infection, defined as: struct Infection { public: explicit Infection( double it, double rt ) : infT( it ), recT( rt ) {} double infT; // in...

"Implicit declaration" warning

For this code: int i=0; char **mainp; for(i=0;i<2;++i) { mainp[i]=malloc(sizeof(char)*200); if(!scanf("%[^#],#",mainp[i])) break; if(i<2) scanf("%[^#],#",mainp[i]); } GCC emits the warnings: warning: implicit declaration of function ‘scanf’ warning: incompatible implicit declaration of built-in function ‘sca...

Segmentation fault in std function std::_Rb_tree_rebalance_for_erase ()

(Note to any future readers: The error, unsurprisingly, is in my code and not std::_Rb_tree_rebalance_for_erase () ) I'm somewhat new to programming and am unsure how to deal with a segmentation fault that appears to be coming from a std function. I hope I'm doing something stupid (i.e., misusing a container), because I have no idea how...

Determine the line of C code that causes a segmentation fault?

How do we determine where the mistake is in our code that causes a segmentation fault? After writing some code, to determine where I have a segmentation fault, can gcc show me my have a mistake (or typing error) in a particular line number -- because that line caused the segmentation fault? ...

why gcc emits segmentation ,after my code run

Every time I run this I encounter a segmentation fault? I have not found my fault as sometimes gcc emits a segmentation fault and sometimes the memory stack limit is exceeded. This is the code. #include <stdio.h> #include <stdlib.h> #include "labheader.h" void my_main() { char *tutar[50],tempc; int i=0,temp,g=0...

casting char[][] to char** causes segfault?

Ok my C is a bit rusty but I figured I'd make my next(small) project in C so I could polish back up on it and less than 20 lines in I already have a seg fault. This is my complete code: #define ROWS 4 #define COLS 4 char main_map[ROWS][COLS+1]={ "a.bb", "a.c.", "adc.", ".dc."}; void print_map(char** map){ int i; for(i=0;...

C -Segmentation fault !

It seems at least weird to me... The program runs normally.But after I call the enter() function for the 4th time,there is a segmentation fault!I would appreciate any help. With the following function enter() I wanna add user commands' datas to a list. [Some part of the code is already posted on another question of me, but I think I s...

Why do I get a segmentation fault while redirecting sys.stdout to Tkinter.Text widget in Python?

I'm in the process of building a GUI-based application with Python/Tkinter that builds on top of the existing Python bdb module. In this application, I want to silence all stdout/stderr from the console and redirect it to my GUI. To accomplish this purpose, I've written a specialized Tkinter.Text object (code at the end of the post). ...

seg fault caused by malloc and sscanf in a function

Hi, 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 everythi...