来自fread()/ calloc的Segfault

时间:2014-02-12 18:51:07

标签: c segmentation-fault fread calloc

我不确定为什么我运行它(使用argv [1]是ppm图像)会导致段错误。有什么想法吗?

unsigned char *image;
char *name;
int sz;

name = argv[1];
FILE *fpt;

fpt = fopen(name,"rb");

fseek(fpt, 0, SEEK_END);
sz = ftell(fpt);
fseek(fpt, 0, SEEK_SET);

image = (unsigned char *) calloc(sz, 1);
fread(image, 1, sz, fpt);

0 个答案:

没有答案