Home > OS >  Why do I get a segmentation fault when using "dialog_checklist" from Linux's "di
Why do I get a segmentation fault when using "dialog_checklist" from Linux's "di

Time:04-14

I wanted to use the dialog.h library from the dialog Linux package but when I try to make a radiolist (checklist with flag parameter set to 1) it gives me a segmentation fault. I assume it has to do with the list of strings (char**) but I have been unable to find a fix for it.

In this code on line 10 the error occurs:

#include <dialog.h>

int main() {
    int distro;
    char dist1[] = "Ubuntu";
    char dist2[] = "Gentoo";
    char *distros[2] = {dist1,dist2};
    init_dialog(stdin, stdout); // start dialog

    distro = dialog_checklist("Select Distro","Select One",0,0,0,2,distros,1);

    end_dialog(); // end dialog
}

Incase anyone needs it: man page for dialog.h

CodePudding user response:

The signature for dialog_checklist is:

int  dialog_checklist(unsigned char *title, unsigned char *prompt, int height,
     int width, int list_height, int cnt, void *it, unsigned char *result);

When I have similar problems, I tend to do go through my call and check each parameter:

    dialog_checklist("Select Distro", // title, ok
                     "Select One",    // prompt, ok
                     0,               // height, ok
                     0,               // width, ok
                     0,               // list_height, ok
                     2,               // cnt, ok
                     distros,         // it, probably ok
                     1);              // result, not an `unsigned char*`, not ok.

Here we see that the last parameter is definitely not ok and that would be my first parameter to correct.

CodePudding user response:

It appears I read the documentation wrong, the list was supposed to contain {tag, item, status} for each item.

  • Related