C libjpeg jpeg_stdio_dest()分段错误

C libjpeg jpeg_stdio_dest()分段错误,c,C,您好,我在将数据写入jpeg时遇到了一个小问题: 以下是代码片段: struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; /* More stuff */ FILE * outfile; /* target file */ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ int row_stride;

您好,我在将数据写入jpeg时遇到了一个小问题:

以下是代码片段:

struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
/* More stuff */
FILE * outfile;                /* target file */
JSAMPROW row_pointer[1];        /* pointer to JSAMPLE row[s] */
int row_stride;                /* physical row width in image buffer */

cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);


if ((outfile = fopen(filename, "wb+")) == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    exit(1);
}
else
    printf("File successfully opened\n");

jpeg_stdio_dest(&cinfo, outfile);

cinfo.image_width = img_w;
cinfo.image_height = img_h;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
它给了我一个关于jpeg\u stdio\u dest、gdb输出的错误:

#0 0x00007FF7855735,位于/usr/lib/libc.so.6的malloc_consolidate()中

#1 0x00007FF7856A08 in_int_malloc(),来自/usr/lib/libc.so.6

#来自/usr/lib/libc.so.6的malloc()中的2 0x00007ffff7858cc0

#3 0x00007FF7BB4B17英寸??()来自/usr/lib/libjpeg.so.8

#4/usr/lib/libjpeg.so.8中jpeg_stdio_dest()格式的0x00007FF7B9F225

#写入jpeg文件中的5 0x0000000000400f2e( 图像缓冲区=0x608070“\002\002\002\002\002\002\002\366\366\365\365\365\365\001\001\001\003\003\371\371\371\371\367\367\362\362\362\361\361\361\361\002\002\003\003\003\373\373\001\001\001\002\002\002\002\002\002\002\001”,img\h=4,img\U w=4,文件名=0xFF7FFG=10X\FFG\FFG=100,质量标准:美国食品及药品监督管理局第39号(美国食品和药品监督管理局,美国食品安全标准协会,美国食品和药品监督管理局,美国食品和药品监督管理局,美国食品及药物管理局,美国药典,美国食品安全标准,美国食品标准

#main中的6 0x0000000000400e1f(argc=5,argv=0x7fffffffe2e8)位于main.c:28


我不知道在哪里搜索,非常感谢您提供的任何帮助

文件打开可能会失败,但您仍可以拨打jpeg\u stdio\u dest电话

支架问题

if ((outfile = fopen(filename, "wb+")) == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    exit(1);
}
else
{
    printf("File successfully opened\n");
    jpeg_stdio_dest(&cinfo, outfile);
}

为什么不在
main.c:28
开始调试?main.c:28是对包含上面代码段的write_jpeg_文件的调用…如果打开失败,program将通过exit(1)退出。此外,使用segfault,我收到文件已成功打开的消息。这是来自动态链接jpeglib的调用,gdb无法查看它,因为它未使用调试符号编译…该函数需要什么权限才能将其写入输出文件?如果您取消了二进制文件权限会发生什么?我使用的是这个示例:正如您所看到的,注释告诉我必须添加“b”。