segmentation-fault

Why do I get a segmentation fault (core dumped) when I try to allocate a 4D array?

I'm trying to allocate a large 4D matrix but I want to do it dynamically. When I just create the static matrix everything works fine so I know I have enough memory for now. However when I try and implement the same thing dynamically it breaks whenever I enter the third dimension and I need to get to a fourth! Can anyone tell me why th...

Why can't I assign values to pointers?

After reading the faq's and everything else I can find, I'm still confused. If I have a char pointer that is initialised in this fashion: char *s = "Hello world!" The string is in read-only memory and I cannot change it like this: *s = 'W'; to make "Wello world!". This I understand, but I can't, for the life of me, understand how to...

Why does g++ compile this?

Recently, after being very tired, I wrote the following code: GLfloat* array = new GLfloat(x * y * z); Which, of course should have been: GLfloat* array = new GLfloat[x * y * z]; (Note the square brackets as opposed to the parenthesis.) As far as I know, the first form is not valid, but g++ compiled it. Sure, it spat out a complet...

long integer as array index in C gives segmentation fault

Hello to all, The following C Code gives a segmentation fault: #include <stdio.h> #include <stdint.h> int main(){ uint32_t *a; uint32_t idx=1233245613; a[idx]=1233; return 0; } How can I use uint32_t as index of an array in C? Or how can I use array like structure which can get uint32_t and 12 digit n...

How can I avoid a segmentation fault while resize a vector like this

I think it is a simple question for you....i am pretty new in c++..... So i have a vector defined like this: vector<vector<float> > big_vector; I read a file and initialized this vector, then the big_wector has about 200,000 elements in it. each is a vector < float > Then I wanted to modify the elements in big_vector, for some elemen...

Pointer issues with basic C file I/O program

#include <stdio.h> #include <stdlib.h> int main() { FILE *fp = fopen("lr.txt", "r"); fseek(fp, 0L, SEEK_END); int size = ftell(fp); fseek(fp, 0L, SEEK_SET); char *lorem_ipsum; int i = 0; lorem_ipsum = (char*) malloc(sizeof(char) * size); while(fscanf(fp, "%s\n", lorem_ipsum) != EOF) { ...

Why is my C++ code causing a segmentation fault well after using the read(...) function?

My application is suspending on a line of code that appears to have nothing wrong with it, however my IDE appears to be suspending on that line with the error: gdb/mi (24/03/09 13:36) (Exited. Signal 'SIGSEGV' received. Description: Segmentation fault.) The line of code simply calls a method which has no code in it. Isn't a segment...

Vector of pointers problem

Hi, I am having quite a bit of trouble with trying to push_back an object of my custom class to a vector of pointers with my custom class as the type. Please see the code below along with the error received. I am using Eclipse with the CDT plugin and OpenCV on windows xp. I have spent so much time trying to find an answer but to no ava...

Why do I get a segmentation fault when calling a virtual method in this code?

I'm still learning C++; I was trying out how polymorphism works and I got a segmentation fault when calling a virtual method. (Note: I didn't mark the destructor as virtual, I was just trying out to see what happens.) Here's the code: #include <iostream> using namespace std; class Base { protected: char *name; public: Base(char ...

How to interpret this debugging error

As a hacker-in-training, I decided to go about making my own string_reverse function that takes a string, allocates memory for a new string, and returns a pointer to a new string, but I'm not getting what I desire, as this returns a segmentation fault. #include <stdio.h> #include <stdlib.h> char* string_reverse(char* string); char* s...

Why am I getting a segmentation fault with this code?

I am getting a segmentation fault while running this code. I can't work out why this is happening - can anyone see a possible reason? (I have already got and initialized the semaphore's shared memory.) My code: #include<stdlib.h> #include<sys/types.h> #include<sys/shm.h> #include<sys/ipc.h> #include<stdio.h> #include<...

Segmentation Fault with pointer-to-pointer with C / Linux.

In the following code I get a segmentation fault: Set *getpar() {...} char function(...) { Set **S; *S = getpar(); /* Segmentation Fault */ ... } But the bizarre thing is that with few changes there is no segmentation fault: Set *getpar() {...} ... char function(...) { Set *S; // One less '*' S = getpar(); // ...

Segmentation fault on string assignment in C++

Take a look at this example function: RuntimeConfiguration* conf_rt_conf() { RuntimeConfiguration *conf; conf = new RuntimeConfiguration(); conf->arch_path="./archive"; conf->err_log="./err_log"; conf->fail_log="./fail_log"; conf->msg_log="./msg_log"; conf->save="html, htm, php"; conf->ignore="jpg, gif";...

Strange integer value causing segmentation fault

I got a function find_nodes() with a loop inside: for (htmlNodePtr current_node=root_node ; current_node!=NULL ; current_node=current_node->next) { if (xmlHasProp(current_node,(xmlChar *)"href")) { if (xmlHasProp(current_node,(xmlChar *)attribute)) { if (strcmp(value, (char *)xmlGetProp(c...

Compiling C++ using -pthreads for Openwrt Linux-Get segmentation fault

Hi. I´m pretty new to programming in C++ and I´m using pthreads. I´m cross compiling my code for OpenWRT but for some reason I get segmentation fault when I run the program on my board but it runs fine on my PC. I suspect that the error occurs in the linking stage of the compilation because I tried a small C program and that worked fine...

C++ std::vector of pointers deletion and segmentation faults

Hello all, I have a vector of pointers to a class. I need to call their destructors and free their memory. Since they are vector of pointers vector.clear() does not do the job.So I went on to do it manually like so : void Population::clearPool(std::vector<Chromosome*> a,int size) { Chromosome* c; for(int j = 0 ;j < size-1;j++) ...

Why am I getting segfaults randomly?

This is quite strange for me, but I'm getting an unexpected and random segmentation fault when I launch my program. Some times it works, some times it crashes.. The debugger of Dev-C++ points me to a line of the file : stl_construct.h /** * @if maint * Constructs an object in existing memory by invoking an allocated * object's ...

How can a glfwSleep() cause a segfault ?

Hi, in my multithraded application, I'm using a sleep() function (the one from the GLFW library): glfwSleep(..); and it apparently leads my application to segfaulting as my call stack shows: #0 76CFC2BC WaitForSingleObjectEx() (C:\Windows\system32\kernel32.dll:??) #1 00000016 ??() (??:??) #2 0000006C ??() (??:??) #3 00000000 ??() (...

RDTSC in C inline assembly causes segmentation fault!

Hi Thanks to some help of you guys I got my little inline assembler program almost there where I want it to have. However, there now seems to happen something very strange with the rdtsc command; basically, I get a segmentation fault when calling it. int timings[64*N]; int main(void) { int i; __asm__ __volatile__ ( "...

Segmentation fault in hpricot

I'm using hpricot to read HTML. I got a segmentation fault error, I googled and some say upgrade to latest version of Ruby. I am using rails 2.3.2 and ruby 1.8.7. How to resolve this error? ...