I want to determine the cause of a sigsegv
Asked Answered
W

2

1

I'm writing an applicaiton for gentoo linux and redhat linux, one of the funciton always crashes on the redhat machine

usleep(100000);
    Display *display;
    display = XOpenDisplay(NULL);
    Window w;
    int x,y,i;
    unsigned m;
    Window root = XDefaultRootWindow(display);
    XQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m);
    XImage *image;
    sleep(1);
    image = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);
    int pixel = XGetPixel(image,x,y);
    printf("\\clr(%i,%i,%i){}\n",x,y,pixel);
    XCloseDisplay(display);

This function always crashes with a segmentation fault on the rhel machine

running the progrma in gdb: Program received signal SIGSEGV, Segmentation fault. 0x000000369942cb48 in ?? () from /usr/lib64/libX11.so.6 Missing separate debuginfos, use: debuginfo-install atk-1.30.0-1.el6.x86_64 cairo-1.8.8-6.el6_6.x86_64 expat-2.0.1-11.el6_2.x86_64 fontconfig-2.8.0-5.el6.x86_64 freetype-2.3.11-15.el6_6.1.x86_64 gdk-pixbuf2-2.24.1-6.el6_7.x86_64 glib2-2.28.8-4.el6.x86_64 glibc-2.12-1.166.el6_7.1.x86_64 gtk2-2.24.23-6.el6.x86_64 libX11-1.6.0-6.el6.x86_64 libXau-1.0.6-4.el6.x86_64 libXcomposite-0.4.3-4.el6.x86_64 libXcursor-1.1.14-2.1.el6.x86_64 libXdamage-1.1.3-4.el6.x86_64 libXext-1.3.2-2.1.el6.x86_64 libXfixes-5.0.1-2.1.el6.x86_64 libXi-1.7.2-2.2.el6.x86_64 libXinerama-1.1.3-2.1.el6.x86_64 libXrandr-1.4.1-2.1.el6.x86_64 libXrender-0.9.8-2.1.el6.x86_64 libXtst-1.2.2-2.1.el6.x86_64 libpng-1.2.49-2.el6_7.x86_64 libselinux-2.0.94-5.8.el6.x86_64 libxcb-1.9.1-3.el6.x86_64 pango-1.28.1-10.el6.x86_64 pixman-0.32.4-4.el6.x86_64 zlib-1.2.3-29.el6.x86_64

unfortunately I cannot install any additional packages(or install from 3rd party repos) for the rhel machines

backtrace: (gdb) bt

0 0x000000369942cb48 in ?? () from /usr/lib64/libX11.so.6

1 0x00000000004048ce in main (argc=2, argv=0x7fffffffe148) at tat.c:92

line 92 is : int pixel = XGetPixel(image,x,y);

the application works fine if that line is removed

thanks

Wreckfish answered 7/1, 2016 at 17:1 Comment(8)
BTW, You know int and unsigned long are not the same, right?Luba
Also, why don't you check for NULL return for XOpenDisplay()?Luba
There is plenty of error handling missing from your code.Milden
Use XGetWindowAttributes to find the real width/heitgh of the screen. Do not use hardcoded values.Flouncing
Besides checking for NULL as commented, the man page for XGetPixel says The image must contain the x and y coordinates. Which you have not checked.Korte
all valid points, I'll work on them thanksWreckfish
You're not checking the values returned by XQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m); and you're just blindly using the value returned by image = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);. Either one of those calls could fail.Salome
@fukanchik, yes that was it thanks, please post this as an answer so I can mark itWreckfish
F
1

Use XGetWindowAttributes to find the real width/heitgh of the screen. Do not use the hardcoded values.

Flouncing answered 7/1, 2016 at 18:45 Comment(0)
L
1

Most likely it is this line returning NULL:

image = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);

Manual Page says: If a problem occurs, XGetImage returns NULL.

However, this error might be triggered by a previous line's error -- as is mentioned in the comments, you should be checking the return values of all these calls for success/failure.

Larner answered 7/1, 2016 at 17:8 Comment(0)
F
1

Use XGetWindowAttributes to find the real width/heitgh of the screen. Do not use the hardcoded values.

Flouncing answered 7/1, 2016 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.