All Questions
Tagged with c segmentation-fault
6,340 questions
-1
votes
0
answers
26
views
segfualt in C with GPU driver in vulkan [closed]
Unhandled exception at 0x00007FFE82E30508 (nvoglv64.dll) in Voxalith.exe: 0xC0000005: Access violation reading location 0x0000000000002068. I am writing a Vulkan application in C this file is device.c ...
1
vote
0
answers
87
views
How to know if a segmentation fault will happen? [closed]
I'm new in c programming and i am wondering if there is any sure way to know if a program will segfault.
I came to know about the "valgrind" function but some of my codes still encounter ...
3
votes
2
answers
84
views
Memory Lifetime within a process
I understand this might be an undefined behavior question, but I'm curious and also trying to understand the reason for the below results
#include <stdio.h>
#include <string.h>
#include &...
1
vote
1
answer
73
views
C: Segmantation fault (core dumped)
While doing the CS50-task recover i finished everything and ran valgrind over it. Valgrind returns a possible segmentation fault, even though I made sure to never access memory, I don't have access to....
3
votes
1
answer
152
views
Segmentation fault disappears after renaming a function
I have a project that was running fine until some updates happened (MacOS and rustc).
Some calls to a library written in C (called from Rust) result in a segmentation fault:
println!("TEST");...
3
votes
0
answers
72
views
replaced C function with assembly, now segfaulting after main exits [duplicate]
Working on an assignment, the premise is essentially implementing provided C functions in assembly and preserving behavior.
The program reads "records" from stdin (char* last_name, char* ...
2
votes
5
answers
135
views
Segmentation fault when executing a Python script in a C program?
I need to execute some python and C at the same time.
I tried using Python.h:
#include <Python.h>
int python_program(char* cwd)
{
char* python_file_path;
FILE* fd;
int run;
...
-4
votes
1
answer
86
views
how to find the root of segmentation fault in C code? [closed]
The below code runs smoothly if clean() is called without the 32 times loop but with this loop it hits a segmentation fault and i can't seem to find out why and where, So i ran it in valgrind and on ...
0
votes
1
answer
60
views
Why doesn't the following recursive function terminate and instead leads to a segmentation fault?
I wrote two versions of a function in c to change the color of a coherent area of white pixels on a canvas by checking the color of the starting coordinate and, if the staring coordinate is white, set ...
0
votes
1
answer
78
views
How can i make a dynamic allocated struct (a variable in it) to be allocated in the main function without changing too much the code?
I'm trying to make a struct that will be used to read "databases", but my problem is that the functions are using a defined variable that cannot be changed:
#define MAX_DATA 512
#define ...
3
votes
2
answers
103
views
Seg fault on string array items after tokenizing in external function
I am trying to build a runtime command line tool and don't get why I get a segmentation fault when I try to tokenize the string input by the user.
In the str_utils.c file, the expression printf("...
0
votes
1
answer
55
views
Segmentation fault when copying tokens to struct fields using strcpy in C function with strtok [closed]
I'm developing a C function to read a single line from a text file, split it into tokens using strtok, and assign each token to specific fields in a struct. However, I'm encountering a segmentation ...
0
votes
2
answers
47
views
SDL_Init() segfaults after somehow calling my close() function?
Why does this code:
/* gcc test.c -o test -lSDL2 -Wall -Wextra */
#include <SDL2/SDL.h>
void close() {
printf("HERE\n");
SDL_Quit();
}
int main() {
SDL_Init(...
1
vote
1
answer
57
views
segfault with no reason in sight while implementing a dsu in c (probably a silly mistake)
#include <stdio.h>
#include <stdlib.h>
typedef struct Parent {
int node;
int sum;
} Parent;
typedef struct DSU {
Parent* parent;
int* rank;
} DSU;
void create_dsu(DSU* ...
1
vote
0
answers
95
views
Segmentation fault due to SIGBUS [closed]
I have written a code, to reverse the words in a string, and it works for some test cases. But the problem is for remaining cases, it returns segmentation fault. When I'm checking for errors, I found ...
-3
votes
1
answer
85
views
How to print a value stored in a variable in C [closed]
How to print a value stored in a variable in C.
I am new in C and I have a little bit of experience in python.
In python if we take num = 30 and if we do print(num). the output is 30.
I want to do the ...
2
votes
1
answer
90
views
curl_easy_cleanup() causes Segfault- why?
I have a function which reads from an url and writes to a file.
I am getting a segfault when calling the curl_easy_cleanup(). I uncommented this call and I am not getting the segfault any more.
...
0
votes
3
answers
72
views
Segmentation Fault during Balancing of violated AVL tree
I try to implement a program that illustrates the basic operation of an AVL tree. Previously I made that code as a Binary Search Tree and extended its operation to act as AVL. The issue comes every ...
1
vote
1
answer
69
views
Simply trying to use opendir() in my program gives me segmentation fault. Im on vscode and in my schools linux sever
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#define MAX 100
int copy(char fileName[], char dirName[])
{
...
1
vote
1
answer
130
views
Why is it called a Segmentation Fault?
I know what a segfault is: for example,
char arr[10];
arr[11]='n';
But why call it a segfault? Is it related to the segments of memory that get pushed onto the stack?
And why is it commonly defined ...
1
vote
0
answers
39
views
Error Segmentation fault when compile code with vsc [closed]
I created this code to simulate the order management of a pastry shop but when i compile the code with vsc i receive the errore:segmentation fault.
Can you help me?
I define those struct
typedef ...
0
votes
1
answer
56
views
fgets and Segmentation Fault
I got this function:
#define DIGITS_MAXIMUM_NUMBER 10
int* read_from_file(const char* file_name)
{
int limit = 101;
int *values = (int *) malloc(sizeof(int) * limit);
FILE *fp ...
1
vote
1
answer
140
views
Why does (right - left) / 2; cause a segmentation fault? [closed]
I have read the following SO post here and understand why I want to use left + (right - left) / 2; vs (right - left)/ 2; to prevent the possibility of a buffer overflow.
I am also curious as to why ...
-4
votes
1
answer
127
views
C: why I get segmentation fault? [closed]
I have the following code. Calling f1 raises segfault, but not f2.
#include <stdlib.h>
#include <stdio.h>
void f1(unsigned char** arr)
{
unsigned char* p = *arr;
*p = 'h';
p++;
...
0
votes
0
answers
73
views
Segmentation fault err but add fprintf() not segmentation fault err
extern void *masu_malloc(size_t size);
extern void masu_free(void *ptr);
extern void *masu_realloc(void *ptr, size_t size);
extern void *masu_calloc(size_t nmemb, size_t size);
void *malloc(size_t ...
0
votes
1
answer
81
views
C code for solving a 15-puzzle gives a segmentation fault when it tries to show the paths for each update to the puzzle
I have a code that is supposed to show the paths in solving a 15-puzzle after showing the initial state and goal state. However, while it does show the initial state and goal state, it gives a ...
0
votes
0
answers
68
views
Incorrect Matrix Multiplication Not Producing Segmentation Fault
I am working on homework assignment 1 for the Performance Engineering of Software Systems course on MIT OCW. The assignment involves debugging some C code designed to multiply matrices. Matrices are ...
4
votes
1
answer
328
views
Understanding the flow of the kernel upon receiving a SIGSEGV for null-dereference
I'm trying to figure out the sequence of things that occur inside the Linux kernel (x86_64, v6.9) when we write these two codes:
// Null-dereference + writing to page zero
*(char *)0 = 0;
// Null-...
0
votes
1
answer
64
views
Why does my C program with any input results in segmentation fault?
I've spent hours of racking my brain on why doesn't this work
#include <stdio.h>
#define MAXLINE 1000
#define TRUE 1
#define FALSE 0
int getLine(char s[], int lim);
void copy(char to[], char ...
-1
votes
3
answers
126
views
C segfault question: if one of two inputs is null, return the other
I have a function that takes two strings and returns another string (if you must know, its my implementation of strjoin).
Now, I want to make it so that if one of the input strings is NULL, it will ...
1
vote
1
answer
80
views
SDL_Quit segmentation fault
I'm on Ubuntu 22.04.4 LTS, and I'm getting into using the SDL2 library, but for some reason calling SDL_Quit() gives me a segmentation fault. Here's the minimum amount of code for which the error ...
-1
votes
1
answer
70
views
Segmentation fault in C BogoSort
I've started learning c and wanted to program bogosort with it. I coded the most parts, but as I started it, I've got a segmentation fault error, but don't know why.
That's my code:
#include <stdio....
0
votes
1
answer
148
views
Segmentation fault with multidimensional arrays whose size is determined at runtime [duplicate]
I created a program that is supposed to read two 3D matrices from a binary file, multiply them, and print the result to a binary file. However, while it successfully compiles, when I run it, it gives ...
0
votes
1
answer
257
views
Segmentation fault (core dumped) in reading a binary file, memmove-vec-unaligned-erms.S: No such file or directory
I am trying to debug a piece of code that reads binary files I created. It seems that when the number of elements to read is higher than a certain treshold, the script I wrote fails.
The file contains ...
-1
votes
1
answer
54
views
enter a substring and a string and remove substring from string in C [duplicate]
I cannot run this following code since getting segmentation fault. In the main i enter a string and a substring, whereas in the function i catch the substring and remove it from the string using ...
0
votes
0
answers
95
views
Why am i getting a segmentation fault in a code for checking palindrome using linked list?
The statements for my questions are:
Write a program to determine whether a linked list is a palindrome or not.
**Input Format:
**
The first line contains integers separated by spaces representing the ...
1
vote
1
answer
57
views
Segmentation fault in using recursive selection sort in C language
I have i have wrote a C program. It should use recursive selection sort but segmentation fault occurs for big input (10000 or more). Debugger says that the segfault happens in findim function, but it'...
-3
votes
1
answer
73
views
Integer array seemingly deallocates itself when passed by reference to a function [closed]
I am trying to make an opengl program. I have made some files to abstract some of it's features. Here is my code:
VAO_t vao[2];
// First Polygon
vaoGen(&vao[0]);
vaoBind(&vao[0]);
int len1;
...
1
vote
1
answer
71
views
fread() is reading the wrong data even though previous chunk were read correctly
Background:
I'm trying to parse layer info from a .goo file (SLA printer file format for Elegoo Mars 4).
Each layer of the 3d model is encoded in a new chunk of binaries stored in goo_layer_definition[...
2
votes
1
answer
88
views
Quicksort segmentation fault
I implemented a quicksort algorithm in C and works properly in vectors with less that 30000 elements. But, it's get a segmentation fault
in line
swap(&vet[sup], &vet[(sup-inf+1)/2]);
with ...
0
votes
1
answer
76
views
Huffman code segfaults on random input but not on text input
(I asked multiple questions to the implementation of the huffman code here, if I ask too many questions please tell me and I'll stop. Any tips on how to learn to find those mistakes myself are ...
1
vote
1
answer
68
views
Segmentation fault while implementing a binary tree in c
I am new to c, but for a project I am implementing a binary tree. here is my code for the functions:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct ...
0
votes
2
answers
76
views
Segmentation core dumped when trying to build a single linklist
I was learning link list concepts in C, as I was building a project that can create a single reverse order list, I am encountering segmentation code dumped again and again. Kindly help me find my ...
0
votes
2
answers
109
views
C memory access Error Segmentation Fault -
uint32_t binDataSize = 0;
void *binData =Snapshot_Recovery(argc, argv, &binDataSize);
snapshot_header *snapPtr = (snapshot_header *)malloc(binDataSize);
printf("bindataSize is %u\n", ...
0
votes
1
answer
91
views
Shared memory pointer causes segfault when trying to set value
I was trying to make a process that access a shared memory segment created by another process. Everything was working fine I can get id of the shared memory segment, the pointer to the segment and I ...
0
votes
2
answers
121
views
My c code is giving unknown segmentation fault
So I am doing the CS50 practice problem of week 4. It's about recovering a JPEG file that has been deleted so you enter the file check for 4 headers (first 3 the same and the 4th can vary but they ...
0
votes
1
answer
102
views
strdup giving weird warning and Segmentation fault
I was working on other project and found, for me, strange behaviour from strdup.
Lets say we have 3 simple files:
foo.h:
#ifndef FOO_H
#define FOO_H
void example(char *a);
#endif //FOO_H
foo.c:
#...
0
votes
1
answer
62
views
Why are types not recognizeable and why is there a segmentation fault? [duplicate]
I'm working on a C project involving abstract syntax tree (AST) structures for a compiler or interpreter. The project aims to parse a programming language and generate AST representations of the code ...
0
votes
1
answer
184
views
Django- Program terminated with signal SIGABRT, Aborted
After upgrading python 3.6 to 3.8 in our django project we started to get core dump file upto 500mb which makes our kubernetes pods restart. There were no logs, no exception.
Upon debugging the core ...
0
votes
2
answers
118
views
strcpy() throwing segmentation fault for unknown reasons
I'm trying to learn socket programming in C, I want to create a server that manages a chat room, to which clients can connect and send messages to everyone else
Here's the server code:
(You can skip ...