libyahoo Segmentation fault [closed]

丶灬走出姿态 提交于 2019-12-11 16:19:11

问题


I wrote this code:

#include <libyahoo2/yahoo2.h>
#include <libyahoo2/yahoo2_callbacks.h>


int main() {
    int id ;
    char username[255] = "slam";
    char password[255] = "ss" ;
    id = yahoo_init(username, password);
    enum yahoo_status mYahoo ;
    mYahoo = YAHOO_STATUS_AVAILABLE ;
    yahoo_login(id , mYahoo );


    return 0;
}

Compile it, gcc -l yahoo2 y.c -o yahoo and run it with ./yahoo gives me a error: Segmentation fault

(gdb) run

Program received signal SIGSEGV, Segmentation fault.
0x001379b1 in yahoo_login (id=1, initial=0) at libyahoo2.c:1735

line 1735 code is:

tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id,
        host, yss->pager_port, yahoo_connected, ccd, 0);

and see this :

(gdb) list YAHOO_CALLBACK
Function "YAHOO_CALLBACK" not defined.

How do I debug this?


回答1:


How do I debug this?

Execute these commands:

(gdb) print yd->client_id
(gdb) print yss->pager_port

My guess would be that one or both of the above commands will fail, because yd or yss is NULL.

If so, the problem is earlier in libyahoo2.c, and it (apparently) doesn't check for errors properly.

The reason you can't list YAHOO_CALLBACK is most likely that it is a macro. Look in libyahoo2/yahoo2_callbacks.h -- it's very likely to be defined there.

Also, your link command line:

gcc -l yahoo2 y.c -o yahoo

is totally bogus. Correct command line should be:

gcc y.c -o yahoo -lyahoo2

You may want to read this explanation to understand why order of sources and libraries on command line matters.



来源:https://stackoverflow.com/questions/9203461/libyahoo-segmentation-fault

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