segmentation-fault

I have a Fortran program that should give segmentation fault but it doesn't

二次信任 提交于 2021-01-28 21:04:39
问题 As simple as the title. I have a student who got a segmentation fault and I was trying to prove him why does this happen. Instead, I ended up wondering why it doesn't. The code is this: program main implicit none real*8, allocatable:: u(:) integer :: i allocate(u(2)) do i=0, 1000 u(i) = i print *, u(i) enddo end program main I would expect this to crash at i=3 , but it doesn't. Compiled with both ifort and gfortran with -O0 to -O3 回答1: What about turning on the bounds checking option for

I have a Fortran program that should give segmentation fault but it doesn't

吃可爱长大的小学妹 提交于 2021-01-28 20:36:15
问题 As simple as the title. I have a student who got a segmentation fault and I was trying to prove him why does this happen. Instead, I ended up wondering why it doesn't. The code is this: program main implicit none real*8, allocatable:: u(:) integer :: i allocate(u(2)) do i=0, 1000 u(i) = i print *, u(i) enddo end program main I would expect this to crash at i=3 , but it doesn't. Compiled with both ifort and gfortran with -O0 to -O3 回答1: What about turning on the bounds checking option for

hiredis SET runs into segmentation fault

走远了吗. 提交于 2021-01-28 18:29:05
问题 I'm trying to SET a struct into Redis with hiredis: struct StatLite { uid_t uid; gid_t gid; mode_t mode; } bool RedisPermissionHandler::Set(std::string path, StatLite stat) { redisReply *reply = (redisReply*)redisCommand(this->redis, "SET %b %b", path.c_str(), (size_t)path.length(), stat, (size_t)sizeof(stat)); freeReplyObject(reply); return true; } However this runs into a segmentation fault somewhere inside hiredis. this->redis , path , and stat have proper values. GET commands work and

pragma pack(push) without corresponding pop leads to stack smashing

好久不见. 提交于 2021-01-28 12:26:21
问题 I used #pragma pack(push, 2) at the beginning of a struct in a header file but forgot the corresponding #pragma pack(pop) . After including this header file, I included fstream. On creating an ofstream object, I am seeing stack smashing. Details of the exact scenario and code are as follows. I was following a C++ course and had written a code for the project. My program was crashing due to stack smashing. I tried to look for any obvious overflow errors but couldn't find any. I changed almost

Segmentation Fault using MPI_Sendrecv with a 2D contiguous array

六月ゝ 毕业季﹏ 提交于 2021-01-28 12:23:12
问题 my problem is quite simple. When using MPI_Sendrecv, its generates systematically a segfault. I had the same problem earlier with the use of 2D array and a basic MPI_Send but finally solved it. As I tried the same solution that work in the last case, this did not change anything. Thus I'm asking help ! So basically, I allocate all my matrix by this code : double** allocateMatrix(int rows, int cols) { double **M; // Row pointer double *Mdata; // Where data will be actually storde M = calloc

trap fails to catch SIGSEGV

旧时模样 提交于 2021-01-28 12:11:01
问题 I'm using this script to test trap: #!/bin/bash trap "echo segfault!" SIGSEGV g++ forever.cpp ./a.out And forever.cpp just runs a recursive function: void forever(){ forever(); } int main(){ forever(); } However it gives Segmentation fault: 11 instead of printing segfault . I'm not sure why. 回答1: The trap statement traps signals received by bash , not its children. The child receives the segfault and will be exiting with an appropriate exit code. You should therefore check the exit code from

Deleting node in linked list - segmentation fault

ⅰ亾dé卋堺 提交于 2021-01-28 11:42:40
问题 Problem requires to delete node from linked list given head pointer of list and the position of node in list to be deleted. More details of question can be found at: https://practice.geeksforgeeks.org/problems/delete-a-node-in-single-linked-list/1 Code returns segmentation fault but not exactly sure where I went wrong. My code is as follows: Node* deleteNode(Node *head,int x) { //Your code here struct Node* temp = head; if(x==0){ //change head head = temp->next; free(temp); } //find previous

LTO causes crash in standard library

北战南征 提交于 2021-01-28 07:54:17
问题 Consider the following program: #include <iostream> #include <string> int main() { std::string s; std::getline(std::cin, s); return 0; } I try to build it with various flags and run as echo foo | ./prog . If I build it with clang 5.0 or gcc 7.1 (or 7.2) with optimization from -O0 to -O3 , it works as expected. But if I add -flto to any of these configurations, it crashes immediately with the following backtrace: /lib64/libc.so.6(+0x721af)[0x7f596b08e1af] /lib64/libc.so.6(+0x77706)

ctypes segfault on OSX only

瘦欲@ 提交于 2021-01-28 02:51:04
问题 I created a very simple C library binding in Python using ctypes. All it does is accept a string and return a string. I did the development on Ubuntu, and everything looked fine. Unfortunately, on OSX the exact same code fails. I'm completely stumped. I've put together a minimal case showing the issue I'm having. main.py import ctypes # Compile for: # Linux: `gcc -fPIC -shared hello.c -o hello.so` # OSX: `gcc -shared hello.c -o hello.so` lib = ctypes.cdll.LoadLibrary('./hello.so') # Call the

freeing argument in function specified in pthread_create

风格不统一 提交于 2021-01-27 23:34:04
问题 I am writing a small server which creates a new thread to handle each new connection. I need to pass the socket to the function using the fourth argument of pthread_create. When trying to free the memory used for the socket i get a segfault. The communication works fine. I have tried passing a void* and also a void** (casted to void*, kind of ugly) This is the latest cludge i'm using while trying to figure this out, later if will be doing actual work in the respond function. #include <sys