Segmentation Fault - Motif

This is a discussion on Segmentation Fault - Motif ; Hi devs, I'm running Fedora Core 4 for AMD64. When executed this motif sample program I've got segmentation fault in the XtVaAppInitialize() function call: /* test_for_echo.c */ #include #include #include #include #include #include #include #include #define MAX_STR_LEN 30 void cmd_cbk(), ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Segmentation Fault

  1. Segmentation Fault

    Hi devs,
    I'm running Fedora Core 4 for AMD64. When executed this motif sample
    program I've got segmentation fault in the XtVaAppInitialize() function
    call:

    /* test_for_echo.c */

    #include
    #include
    #include
    #include
    #include

    #include
    #include

    #include

    #define MAX_STR_LEN 30

    void cmd_cbk(), /* Widget, XtPointer*, XmAnyCallbackStruct*), */
    quit_cbk(); /* Widget, int); */

    Widget msg_wid;

    char* cmd_label = "Command Area: ";
    char* msg_label = "Message Area: ";

    int cmd_label_length;
    int msg_label_length;

    int main(int argc, char** argv)
    {
    Widget top_wid, main_win, menubar, menu,
    label, cmd_wid;
    XtAppContext app;
    XmString label_str, quit;

    cmd_label_length = strlen(cmd_label);
    msg_label_length = strlen(msg_label);

    printf("here...\n");

    top_wid = XtVaAppInitialize(&app, "main_window", 0, 0, &argc, argv, 0,
    0);

    printf("here...\n");

    main_win = XtVaCreateWidget("main_w",
    xmMainWindowWidgetClass, top_wid,
    XmNcommandWindowLocation, XmCOMMAND_BELOW_WORKSPACE,
    0);

    printf("here...\n");

    quit = XmStringCreateLocalized("Quit");
    menubar = XmVaCreateSimpleMenuBar(main_win, "menubar",
    XmVaCASCADEBUTTON, quit, 'Q', 0);

    printf("here...\n");

    XmStringFree(quit);
    XtManageChild(menubar);

    label_str = XmStringCreateLocalized("Work Area");

    label = XtVaCreateManagedWidget("main_window",
    xmLabelWidgetClass, main_win,
    XmNlabelString, label_str,
    XmNwidth, 1000,
    XmNheight, 800,
    0);

    XmStringFree(label_str);

    cmd_wid = XtVaCreateWidget("Command",
    xmTextFieldWidgetClass, main_win,
    XmNmaxLength, MAX_STR_LEN, 0);

    XmTextSetString(cmd_wid, cmd_label);
    XmTextSetInsertionPosition(cmd_wid, cmd_label_length);

    XtAddCallback(cmd_wid, XmNactivateCallback, cmd_cbk, 0);

    printf("here again...\n");

    msg_wid = XtVaCreateWidget("Message:",
    xmTextFieldWidgetClass, main_win,
    XmNeditable, False,
    XmNmaxLength, MAX_STR_LEN,
    0);

    XmTextSetString(msg_wid, msg_label);

    XtManageChild(msg_wid);

    XtVaSetValues(main_win,
    XmNmenuBar, menubar,
    XmNworkWindow, label,
    XmNcommandWindow, cmd_wid,
    XmNmessageWindow, msg_wid,
    0);

    XtManageChild(main_win);
    XtRealizeWidget(top_wid);
    XtAppMainLoop(app);
    }

    void cmd_cbk(Widget cmd_widget, XtPointer* client_data,
    XmAnyCallbackStruct* cbs)
    {
    char cmd[MAX_STR_LEN], msg[MAX_STR_LEN];

    XmTextGetSubstring(cmd_widget, cmd_label_length,
    MAX_STR_LEN - cmd_label_length, MAX_STR_LEN, cmd);

    XmTextReplace(msg_wid, msg_label_length, MAX_STR_LEN, cmd);

    XmTextSetString(cmd_widget, cmd_label);
    XmTextSetInsertionPosition(cmd_widget, cmd_label_length);
    }

    void quit_cbk(Widget w, int item_no)
    {
    if(item_no == 0)
    exit(0);
    }

    /* ends here */

    I'm using openmotif-2.2.3-10 package. Other motif programs were running
    fine.

    My command line is:
    gcc -o test_for_echo ./test_for_echo.c -lXm -L/usr/X11R6/lib64

    Is my source code fine ? Is it a bug in Motif Library.

    Thanx in advance,
    Ashish Shukla alias Wah Java !!

    Wah Java !!


  2. Re: Segmentation Fault

    WahJava wrote:

    > I'm running Fedora Core 4 for AMD64. When executed this motif sample
    > program I've got segmentation fault in the XtVaAppInitialize() function
    > call:


    0 is not a pointer in vararg calls, use (void*)0 or NULL.

  3. Re: Segmentation Fault

    Respected ST,

    Thanx it worked. I don't know this earlier.

    Thanx

    Ashish Shukla alias Wah Java !!

    Wah Java !!


+ Reply to Thread