segmentation-fault

segmentation fault in C during scanf

余生颓废 提交于 2019-12-17 21:23:30
问题 I am trying to scan in an integer to use for my program. However my program gives me segmentation fault during compilation this is the section that is giving me the error: int main(void) { int totalHeight=0, floorWidth=0, amountOfStories, amountWindowForTop, amountWindowForMiddle, amountWindowForBottom, windowHeight, middleWindowWidth, topWindowWidth, bottomWindowWidth, minimumHeight, minimumWidth; char topFloorWindowContent, middleFloorWindowContent, bottomFloorWindowContent, windowBorder,

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7f4485ff1820

不打扰是莪最后的温柔 提交于 2019-12-17 20:37:36
问题 My app has been crashing randomly with signal 11. I was able to get my hands on tombstone file from emulator but I am not able to understand what is wrong with my app. I have gone through many posts here with the same error but haven't found a working solution yet. I am attaching my stack-trace file here please help me understand the problem and how can I fix it. Here is logcat from the crash --------- beginning of crash 12-15 21:09:25.003 2865-2875/in.myapp.dev A/libc: Fatal signal 11

Passing std::filesystem::path to a function segfaults

岁酱吖の 提交于 2019-12-17 20:14:37
问题 When I attempt to use std::filesystem::path as a function argument, it segfaults on my machine. Here is a minimal example: #include <filesystem> void thing(const std::filesystem::path& p) { return; } int main() { thing("test"); return 0; } This snippet results in the following backtrace from gdb: #0 0x0000563a5a3814b3 in std::vector<std::filesystem::__cxx11::path::_Cmpt, std::allocator<std::filesystem::__cxx11::path::_Cmpt> >::~vector (this=0x23, __in_chrg=<optimized out>) at /usr/include/c++

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

ぐ巨炮叔叔 提交于 2019-12-17 19:12:02
问题 I'm trying to execute a Python script, but I am getting the following error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) I'm using python 3.5.2 on a Linux Mint 18.1 Serena OS Can someone tell me why this happens, and how can I solve? 回答1: The SIGSEGV signal indicates a "segmentation violation" or a "segfault". More or less, this equates to a read or write of a memory address that's not mapped in the process. This indicates a bug in your program. In a Python program

Segmentation fault around strcpy?

狂风中的少年 提交于 2019-12-17 19:02:03
问题 I know that you will rap me over the knuckles but. Why does it make Segmentation fault char* cmd; strcpy(cmd, argv[0]); when this doesn't char *cmd; cmd = "plop"; I didn't practice since a while, and can't remember why. ps: actually, i know that something like that, before the strcpy, would be better char *cmd = (char*) malloc(strlen(argv[0])); but i'm just wondering why this segmentation fault. Thanks ! 回答1: When you do: char * cmd; You're allocating a pointer on the stack . This pointer is

Executing machine code in memory

走远了吗. 提交于 2019-12-17 17:33:49
问题 I'm trying to figure out how to execute machine code stored in memory. I have the following code: #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { FILE* f = fopen(argv[1], "rb"); fseek(f, 0, SEEK_END); unsigned int len = ftell(f); fseek(f, 0, SEEK_SET); char* bin = (char*)malloc(len); fread(bin, 1, len, f); fclose(f); return ((int (*)(int, char *)) bin)(argc-1, argv[1]); } The code above compiles fine in GCC, but when I try and execute the program from the command

What is SEGV_MAPERR?

让人想犯罪 __ 提交于 2019-12-17 15:22:06
问题 What is SEGV_MAPERR , why does it always come up with SIGSEGV ? 回答1: There are two common kinds of SEGV, which is an error that results from an invalid memory access: A page was accessed which had the wrong permissions. E.g., it was read-only but your code tried to write to it. This will be reported as SEGV_ACCERR. A page was accessed that is not even mapped into the address space of the application at all. This will often result from dereferencing a null pointer or a pointer that was

segfault only when NOT using debugger

感情迁移 提交于 2019-12-17 15:16:09
问题 I have a multithreaded C program, which consistently generates a segmentation fault at a specific point in the program. When I run it with gdb, no fault is shown. Can you think of any reason why the fault might occur only when not using the debugger? It's pretty annoying not being able to use it to find the problem! 回答1: Classic Heisenbug. From Wikipedia: Time can also be a factor in heisenbugs. Executing a program under control of a debugger can change the execution timing of the program as

Segmentation Fault when attempting to print value in C

谁都会走 提交于 2019-12-17 14:50:07
问题 The following C code returns a "segmentation fault" error. I do not understand why it does not return the value 20. What is my error? #include <stdio.h> int main() { int* n; *n = 20; printf("%i\n",*n); return 0; } 回答1: You haven't allocated memory to n , so *n = 20; attempts to write unspecified memory. Try #include <stdlib.h> int *n = malloc(sizeof *n); /* use n */ free(n); 回答2: You haven't allocated space for your int , you've only declared a pointer to an int . The pointer is uninitialized

Segmentation Fault when attempting to print value in C

泪湿孤枕 提交于 2019-12-17 14:49:44
问题 The following C code returns a "segmentation fault" error. I do not understand why it does not return the value 20. What is my error? #include <stdio.h> int main() { int* n; *n = 20; printf("%i\n",*n); return 0; } 回答1: You haven't allocated memory to n , so *n = 20; attempts to write unspecified memory. Try #include <stdlib.h> int *n = malloc(sizeof *n); /* use n */ free(n); 回答2: You haven't allocated space for your int , you've only declared a pointer to an int . The pointer is uninitialized