segmentation-fault

CS50 recover segmentation fault Oct 2020

偶尔善良 提交于 2021-01-27 19:13:00
问题 I'm new to coding and started with Harvard's CS50 course. I've written some code for recover for cs50, and tried to run it, but segmentation fault occurs. In need of some help in identifying what's wrong. #include <stdio.h> #include <stdlib.h> #include <stdint.h> typedef uint8_t BYTE; int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: ./recover image\n"); return 1; } FILE *file = fopen(argv[1], "r"); if (file == NULL) { printf("Usage: ./recover image\n"); } char filename[8];

Segmentation fault when calling sdp_record_register()

醉酒当歌 提交于 2021-01-27 15:42:35
问题 I'm trying to register my Bluetooth service in SDP using BlueZ. I follow this tutorial. Code compiles successfully but when I run it, I get a segmentation fault (even with the code copy-pasted from the tutorial). Part of stack trace: { "address": 140382101864854 , "build_id": "a629c43f58d471aa12e35d3e63ee264c514a21ac" , "build_id_offset": 86422 , "function_name": "sdp_device_record_register_binary" , "file_name": "/lib64/libbluetooth.so.3" } , { "address": 140382101865504 , "build_id":

Segmentation fault in C

末鹿安然 提交于 2021-01-27 12:50:26
问题 I need to fill 2-d array with 0s. But compiled program falls with this error. What's wrong? int main() { int vert[1001][1001]; int hor[1001][1001]; int dudiag[1416][1416]; int uddiag[1416][1416]; int n, k, m; int row, col; int i, j; int answer = 0; for(i = 0; i <= 1000; i++){ for(j = 0; j <= 1000; j++){ vert[i][j] = 0; hor[i][j] = 0; } } ... } When cycle is commented out, it works properly. 回答1: The problem is that you are trying to allocate too much memory in the automatic store (AKA "on the

Bewildering SegFault involving STL sort algorithm

六眼飞鱼酱① 提交于 2021-01-27 05:41:24
问题 I am trying to recreate the program in Column 15 of programming pearls using the STL. I am trying to create a suffix array using a string and a vector of indices. I record the list of words that I read in a string called input that acts as a list of words separated by ' ' that I read from stdin at the beginning of the program. Everything works as expected until I get to the sorting portion of the code. I'd like to use the STL's sort algorithm, but I am completely perplexed at a seg fault that

understanding stack trace of a segmentation fault

余生长醉 提交于 2021-01-27 05:34:32
问题 I am doing an snprintf and getting a seg fault. when I loaded the core file on gdb like this: gdb my_executable core ; and did bt to get the backtrace, I got following: Program terminated with signal 11, Segmentation fault. #0 0x88207fc2 in memcpy () from /usr/lib/libc.so.6 (gdb) bt #0 0x88207fc2 in memcpy () from /usr/lib/libc.so.6 #1 0x88205eb6 in __sfvwrite () from /usr/lib/libc.so.6 #2 0x881fbc95 in strchr () from /usr/lib/libc.so.6 #3 0xbfbe6c14 in ?? () #4 0xbfbe69d8 in ?? () #5

Segfault in std::atomic load?

╄→尐↘猪︶ㄣ 提交于 2021-01-27 04:27:28
问题 On linux, using gcc 4.8.4, compiled with -std=c++11 -mcx16: #include <atomic> struct node_t; struct pointer_t { node_t* ptr; unsigned int count; pointer_t() noexcept : ptr{nullptr}, count{0} {} }; struct empty {}; struct node_t { empty value; std::atomic<pointer_t> next; node_t() : next{pointer_t{}} {} }; int main() { node_t{}.next.load(); return 0; } gives a segfault when load is called. How am I meant to initialize an atomic value? 回答1: Turns out this is a bug in gcc that has since been

std::function bad memory access when creating a temporary

寵の児 提交于 2021-01-27 04:11:06
问题 I'm currently implementing few abstractions to represent level-set operations for 3D objects. Basically what is described in this amazing page for GLSL shaders. To give a brief overview, a 3D object can be described by a function that maps the R^3 domain to a scalar called level-set (or signed-distance-function). For example, for a sphere, the level-set function is defined by phi(X) = X.Norm2() - R*R where Norm2 represents the squared Euclidean norm of a vector in R^3. So I came out with a

std::function bad memory access when creating a temporary

你说的曾经没有我的故事 提交于 2021-01-27 04:10:05
问题 I'm currently implementing few abstractions to represent level-set operations for 3D objects. Basically what is described in this amazing page for GLSL shaders. To give a brief overview, a 3D object can be described by a function that maps the R^3 domain to a scalar called level-set (or signed-distance-function). For example, for a sphere, the level-set function is defined by phi(X) = X.Norm2() - R*R where Norm2 represents the squared Euclidean norm of a vector in R^3. So I came out with a

std::function bad memory access when creating a temporary

て烟熏妆下的殇ゞ 提交于 2021-01-27 04:08:48
问题 I'm currently implementing few abstractions to represent level-set operations for 3D objects. Basically what is described in this amazing page for GLSL shaders. To give a brief overview, a 3D object can be described by a function that maps the R^3 domain to a scalar called level-set (or signed-distance-function). For example, for a sphere, the level-set function is defined by phi(X) = X.Norm2() - R*R where Norm2 represents the squared Euclidean norm of a vector in R^3. So I came out with a

Access Base class variable from child class method

自古美人都是妖i 提交于 2021-01-20 19:43:15
问题 How can I access base class variable from a child method? I'm getting a segmentation fault. class Base { public: Base(); int a; }; class Child : public Base { public: void foo(); }; Child::Child() :Base(){ void Child::foo(){ int b = a; //here throws segmentation fault } And in another class: Child *child = new Child(); child->foo(); 回答1: It's not good practice to make a class variable public. If you want to access a from Child you should have something like this: class Base { public: Base():