Segfault on the code below, where is the error?

Advertisements The code: #include <list> #include <thread> #include <sys/poll.h> struct xsk_ring_stats { unsigned long rx_frags; unsigned long rx_npkts; unsigned long tx_frags; unsigned long tx_npkts; unsigned long rx_dropped_npkts; unsigned long rx_invalid_npkts; unsigned long tx_invalid_npkts; unsigned long rx_full_npkts; unsigned long rx_fill_empty_npkts; unsigned long tx_empty_npkts; unsigned long prev_rx_frags; unsigned long prev_rx_npkts; unsigned long prev_tx_frags; unsigned long prev_tx_npkts; unsigned… Read More Segfault on the code below, where is the error?

How to initialize a 2d array of pointers to point to the same pointers as another given one

Advertisements I’m new to C, trying to learn it by coding real things instead of isolated and naive book examples. I’m struggling a lot with understanding pointers correctly. My books aren’t really helping. I’ve got an array of pointers which i’m initializing the following way: struct Node **cols; cols = (struct Node *) calloc(N_RESTRICTIONS, sizeof(struct… Read More How to initialize a 2d array of pointers to point to the same pointers as another given one

How to overcome Segfault on accessing pointer to array

Advertisements Segfault on accessing pointers I’m developing simple GTK3 C app (using WSL2 and VSCode), but when I try to deserialize structs from file I’m getting Segfault (I’m not really familiar with gdb, so when I tried to debug I couldn’t really find the line which causes error). My Code Struct definition typedef struct whatev… Read More How to overcome Segfault on accessing pointer to array

C gives segmentation fault and a warning for two different lines. What can I do to solve this issue?

Advertisements I’m still a beginner in C, but as training I would like to create a Password Manager(a very bad on though). First a .txt file is created, and then the user is given an option of what they would like to do next. Using strcmp I make the program decide what function to execute… Read More C gives segmentation fault and a warning for two different lines. What can I do to solve this issue?

C++ returning an rvalue doesn't work and segfault

Advertisements I have a function what creates a vector, does somthing with it and then return it as an rvalue using std::move. When I am assigning it to a variable, I’m expecting to call std::vector‘s move constructor std::vector::vector(vector&&). But I’m getting a segmentation fault. Here’s my code: #include <iostream> #include <vector> std::vector<int>&& getVector(int start) {… Read More C++ returning an rvalue doesn't work and segfault

std::pair returned by std::transform resulting in segfault

Advertisements I’m trying to transform a vector of strings to a vector of pairs of strings, and I was getting segfault. I’ve tried to narrow it down to a simple test case (below), and I’m sure it’s likely to do with the memory allocation: #include <string> #include <vector> #include <utility> std::pair<std::string, std::string> newP( const std::string&… Read More std::pair returned by std::transform resulting in segfault