开发者

Seg Fault With libjpeg

I can't make any sense of the segmentation fault I'm getting out of the following code:

#include <stdio.h> 
#include <jpeglib.h>
#include <stdlib.h>

int main(int argc, char** argv){
    FILE*                   outfile;
    JSAMPLE*                row_pointer;
    struct jpeg_error_mgr   jerr;
    long long int           *w, *h;

    setSomePointers(w, h);

    printf( "%lld  %lld\n", *w, *h);
}

Commenting out any one of the first three declarations will fix it...

Oddly, the following code works:

#include <stdio.h> 
#include <jpeglib.h>
#include <stdlib.h>

int main(int argc, char** argv){
    FILE*                   outfile;
    JSAMPLE*                row_pointer;
    struct jpeg_error_mgr   jerr;
    long long int           w, h;

    setSomePointers(&w, &a开发者_StackOverflowmp;h);

    printf( "%lld  %lld\n", w, h);
}

Is there something strange happening, or do I need to hit some C tutorials?


This is totally undefined behavior - you dereference uninitialized pointers.

The actual problem is in

printf( "%lld  %lld\n", *w, *h);

The other things are just declarations. You should not dereference w and h, as they are not initialized at all. This has nothing to do with commenting/uncommenting any of the first (3) lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜