segmentation-fault

Whats wrong with this program?

char *s = "hello ppl."; for (i = 0; i < strlen(s); i++) { char c = s[i]; if (c >= 97 && c <= 122) { c += 2; s[i] = c; } } I want to rotate the string by two characters: "hello ppl." -> "jgnnq rrn." I am getting a segmentation fault. What is wrong with the code? ...

Segmentation fault, using pointers to pointers

So I'm starting my magic square hw, where I ask the user to enter a odd integer, and it will create a magic square off that. I have to use pointers and arrays as that is all I have learned so far. Not asking how to do the magic square, but what is causing a segmentation fault, im probably not doing pointers to 2d arrays correctly #inclu...

Mysql_num_rows() Segfaults

I'm writing a program using C++ and the MySQL C API (version 5.1.31 ubuntu2). However, if the query is UPDATE then I get a Segmentation Fault error when executing the line "RowsReturned = mysql_num_rows( Result );". //this code snippet contains only the relevant code MYSQL_RES *Result; long RowsReturned; MYSQL_RES *MYSQLDB::RunQuery( c...

Help with segmentation fault in struct

Hello. I am having trouble debugging my code. I have a struct and a function to compute the time difference entered in HH:MM:SS format. My code is: const int hourConv = 3600; // used to get total hours from total seconds const int minConv = 60; struct MyTime { int hours, minutes, seconds; }; MyTime *determineElapsedTime(c...

What is causing this segmentation fault while using SSE instructions?

This problem is driving me a bit crazy. The code seems to be segmentation faulting for no good reason: #define MULT_FLOAT4(X, Y) ({ \ asm volatile ( \ "movups (%0), %%xmm0\n\t" \ "mulps (%1), %%xmm0\n\t" \ "movups %%xmm0, (%1)" \ :: "r" (X), "r" (Y)); }) int main(void) { int before; float a[4...

Segmentation fault on time(0);

Hi! I'm rewriting an old program to do some new stuff, and suddenly I get a segmentation fault error on the following line of code: time_t seconds_since_time_begun = time(0); Why, oh why? Update: I have included the time.h header file in my code, and when I tried what pmg suggested below, both variables were 4 in size. When I tried...

Why does Linux program that derefrences (char*)0 not always segfault?

I'm testing code that is designed to detect when a child process has segfaulted. Imagine my surprised when this code does not always segfault: #include <stdio.h> int main() { char *p = (char *)(unsigned long)0; putchar(*p); return 0; } I'm running under a Debian Linux 2.6.26 kernel; my shell is the AT&T ksh93 from the Debian k...

Segmentation fault only when running on multi-core

I am using a c++ library that is meant to be multi-threaded and the number of working threads can be set using a variable. The library uses pthreads. The problem appears when I run the application ,that is provided as a test of library, on a quad-core machine using 3 threads or more. The application exits with a segmentation fault runtim...

C: Accessing a pointer from outside a function

I have the following code: int takeEven(int *nums, int numelements, int *newlist) { newlist = malloc(numelements * sizeof *newlist); int i, found = 0; for(i = 0; i < numelements; ++i, nums++) { if (!(*nums % 2)) { *(newlist++) = *nums; found++; } } newlist -= found; printf(...

Boost.Python + OpenGL segmentation faults

I have a (almost) perfectly working C++ code written with Boost.Python. It wraps a shared pointer based structure hierarchy of 3 or 4 classes, nothing terribly complex (i.e. class A has a std::vector of class B instance pointers, etc.), top level package called, say, foo. Some time ago I decided to add visualization to the project using...

Segmentation Fault - Adaptive Huffman Tree

I am trying to implement the adaptive huffman code, but while trying to build the tree i get a segmentation fault when executing the code at line "currentNYT->lchild = newNYT;" in addnode() function. Could anyone please help me out? It might be something simple i'm not aware of. didn't use C for a while now. //variable and type declara...

Segmentation Fault - Displaying Tree

I get a segfault when calling viewTree(root); struct treeElement { unsigned long weight; unsigned short id; char chr; struct treeElement *lchild, *rchild, *parent; }; typedef struct treeElement node; node *root; //INITIALIZE TREE void initTree() { root = malloc(sizeof(no...

C++ segmentation fault when trying to output object functions

I am attempting to output functions common to a set of objects that share a base class and I am having some difficulty. When the objects are instantiated they are stored in an array and then I am attempting with the following code to execute functionality common to all the objects in this loop: if ( truck <= v ) // all types of truck...

Weird PHP segfault

I discovered a way to make php segfault, and I'm a bit curious about what's happening. Maybe someone can explain this for me? joern@xps:..com/trunk5/tools/nestedset> cat > while.php <?php while(1){ die('dd'); } ?> ^C 0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php ddzsh: segmentation fault php -f while.php 0 joern...

Causing push_back in vector<int> to segmentaion fault on what seems to be simple operation

I'm working on a program for Project Euler to add all the digits of 2^1000. So far I've been able to track the program segmentation faults when it reaches around 5 digits and tries to push a one onto the vector at line 61 in the function carry(). #include <iostream> #include <vector> #include <string> using namespace std; class MegaN...

Segmentation Fault With Char Array and Pointer in C on Linux

So I have the following program: int main(){ char* one = "computer"; char two[] = "another"; two[1]='b'; one[1]='b'; return 0; } It segfaults on the line "one[1]='b'" which makes sense because the memory that the pointer "one" points to must be in read only memory. However, the question is why doesn't the line "two[1]='b'" s...

PHP doesn't handle stack overflow?

I was surprised when I just tried the following PHP code: function foo() { foo(); } foo(); I expected to get "500: Internal server error". Instead the connection was closed immediately (no bytes received), and the log files show that apache segfaulted. WTF? Is this a known bug in PHP? Are there some configuration options that I'm ...

Why would buffer overruns cause segmentation faults when accessing an integer?

During a call to function B() from function A(), B() allocates a 100-char array and fills it several times, including once with a 101-character string and once with a 110 character string. This is an obvious mistake. Later, function A() tries to access completely unrelated int variable i, and a segmentation fault occurs. I understand ...

Segmentation fault on large array sizes

The following code gives me a segmentation fault when run on a 2Gb machine, but works on a 4GB machine. int main() { int c[1000000]; cout << "done\n"; return 0; } The size of the array is just 4Mb. Is there a limit on the size of an array that can be used in c++? ...

Signal 11, segmentation fault on iphone App exit

I have an iphone app. It seems to run fine. When I connect to a provisioned iphone to Xcode and run the App, the console log in the Organizer window, always complains about a Segmentation fault when quitting the app with the home key. Has anyone else seen this, and do you have an idea of what the problem might be? I use a thread to l...