[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[fol] Re: "ncurses"--help needed......


Hi.

In <93mf5j$867 _at_ nntpa.cb.lucent.com>,
  on Fri, 12 Jan 2001 13:57:25 +0530,
 "Nitin" <nitin_manohar _at_ yahoo.com> wrote:

>   I'm using menu library of ncurses library for development of a tool. While
>  executing a
>  program segmentation fault is coming, and core dumped. After several checks
>  I'm not able to find the bug. I'm running on RedHat Linux 6.2 and SuSE
>  Linux.

Though I had not used this library, this bug in the code is not so
difficult one to solve.

I'm using Debian 2.2, and it has a man page for new_menu
("man -7 3menu new" shows this page).

And it is written that

       The  function  new_menu  creates a new menu connected to a
       specified item pointer array (which  must  be  NULL-termi-
       nated).

>  In the following program while execution of the instruction
>  menu[0] = new_menu(myitem);
>  segmentation fault is coming...
> 
>  Program:
>  ------------------------------------------------
(snip)
>  ITEM * myitem[2];

>  if((myitem[0] = new_item("Menu", "love")) == NULL ){
>   printf("\n Error on new item");
>   exit(1);
>  }
> 
>  if((myitem[1] = new_item("Menu-2nd", "love")) == NULL ){
>   printf("\n Error on 2nd new item");
>   exit(1);
>  }
> 
>  initscr(); /* Initilise the Curses*/
> 
>  menu[0] = new_menu(myitem); / * Here segmentation fault is coming......core
>  dumped*/

Where your code does not have the NULL-terminated item pointer array,
hence the core dump.

Increase the array size to 3 (ITEM * myitem[3];) and initialize to
the last item to null (myitem[2] = (ITEM *)NULL;) before calling
new_menu() fix the core dump, and the menu is shown on my screen.

Regards.
-- 
  Taketoshi Sano: <kgh12351 _at_ nifty.ne.jp>

この情報があなたの探していたものかどうか選択してください。
yes/まさにこれだ!   no/違うなぁ   part/一部見つかった   try/これで試してみる

あなたが探していた情報はどのようなことか、ご自由に記入下さい。特に「まさにこれだ!」と言う場合は記入をお願いします。
例:「複数のマシンからCATV経由でipmasqueradeを利用してWebを参照したい場合の設定について」
References: