[Top][All Lists]

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

Re: ncursesa bug hangs whole system

From: Thomas Dickey
Subject: Re: ncursesa bug hangs whole system
Date: Sat, 05 Jan 2013 15:58:24 -0500
User-agent: Mutt/1.5.20 (2009-06-14)

On Sat, Jan 05, 2013 at 05:52:14PM +0100, address@hidden wrote:
> Hi,
> There is a bug in ncurses which hangs whole system, and hard reset
> is required. See attached file for sample code which causes it. I
> found it using Linux CentOS 5 and ncurses 5.9. Additionally when I
> run it on Virtual PC, I found that system started consuming whole
> CPU after that program was run.
> For sure my program needs fix (it should not pass negative value to
> newwin), but there is also something to fix inside ncurses.

maybe/maybe not:

The second call to newwin returns a null pointer (no window was created).
Passing a null pointer to wgetch() returns an error.

Since there is no input to block (wait) on, the call returns immediately.
That accounts for the high CPU usage, but it is working as documented
in the manpage:

       All  routines  return the integer ERR upon failure and an integer value
       other than ERR (OK in the case of ungetch())  upon  successful  comple-

                   returns an error if there is no more room in the FIFO.

                   returns  an  error if the window pointer is null, or if its
                   timeout expires without having any data.

What do you suppose ncurses should do instead?

> Regards,
> Daniel

> #include <ncurses/curses.h>
> int main()
> {
>     initscr();
>     refresh();
>     WINDOW* win1 = newwin(37, 30, 0, 0);
>     WINDOW* win2 = newwin(-1, 80, 37, 0);

win2 is null.
>     for (int n = 0; n < 36; ++n)
>         wprintw(win1, "test\n");
>     wprintw(win2, "test\ntest");
>     wrefresh(win1);
>     wrefresh(win2);

wrefresh ignores the null win2 parameter
>     cbreak();
>     noecho();
>     char c = 0;
>     while (c != '\n')
>     {
>         c = wgetch(win2); // This line hangs whole system

wgetch returns ERR (immediately)

>         putchar(c);
>         wrefresh(win2);
>     }
>     endwin();
>     return 0;
> }

Thomas E. Dickey <address@hidden>

Attachment: signature.asc
Description: Digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]