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>
References:
- Prev by Date: [fol] Re: 「ブートに関しての8GBの壁」は突破できるか
- Next by Date: [fol] Re: [Q] W3 on emacs20 における日本語表示
- Previous by thread: [fol] Re: "ncurses"--help needed......
- Next by thread: [fol] ,C.A-B`L`E, .B-O`X` ;D`E`S,C;R,A.MB;L,E.R- S,E.E; A-L`L` `T`H`E` `CH-A;NN.EL,,S;;,,,;,,,,;,,;, 2248
- Indexes:[Main][Thread]