terminated by signal SIGSEGV in C

▼魔方 西西 提交于 2019-12-12 03:26:43

问题


I was writing a C program that reads the width and heights of a bmp image following (http://smsoftdev-solutions.blogspot.com.au/2014/07/code-for-reading-bmp-image-files.html). But I've met an error in terminal, it shows that:

i './a.out' terminated by signal SIGSEGV (Address boundary error)

I did some googling, they mention it's accessing extra memory problem, but I can't really find that in my code, any suggestion would be appreciated

#include <stdio.h>

struct __attribute__((__packed__)) BitmapHeader
{
    int width; 
    int height; 
};


void loadBmp(char* filePath, struct BitmapHeader bmpHeaderInfo){
    FILE* filePtr = fopen(filePath, "rb");

    unsigned char header[54];
    fread(header, sizeof(unsigned char), 54, filePtr);
}

int main(){
    char path2BMP[] = "/cup.bmp";
    struct BitmapHeader bmpHeaderInfo = {0};
    loadBmp(path2BMP, bmpHeaderInfo);
    return 0;
}

来源:https://stackoverflow.com/questions/36326567/terminated-by-signal-sigsegv-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!