qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] fix curses update
@ 2010-04-20  9:38 Bernhard Kauer
  2010-04-22  1:27 ` andrzej zaborowski
  0 siblings, 1 reply; 7+ messages in thread
From: Bernhard Kauer @ 2010-04-20  9:38 UTC (permalink / raw)
  To: qemu-devel

If a terminal is resized or the VGA model issues a full refresh, curses_update()
is called, which uses mvwaddchnstr() to draw a full line of characters.  Unfortunatelly
this routine expects a null-terminated string and early aborts if a null is present
in the line. 

When booting an OS that zeros the VGA text buffer and later pokes single characters,
the console output can become unreadable.  The attached patch corrects this bug.


	Bernhard Kauer



Signed-off-by: Bernhard Kauer <kauer@tudos.org>

diff --git a/curses.c b/curses.c
index ed3165e..9bf9265 100644
--- a/curses.c
+++ b/curses.c
@@ -48,10 +48,12 @@ static int px, py, sminx, sminy, smaxx, smaxy;
 static void curses_update(DisplayState *ds, int x, int y, int w, int h)
 {
     chtype *line;
+    int i;
 
     line = ((chtype *) screen) + y * width;
     for (h += y; y < h; y ++, line += width)
-        mvwaddchnstr(screenpad, y, 0, line, width);
+      for (i = 0; i < width; i++)
+	mvwaddch(screenpad, y, i, (line[i] & 0xff) ? line[i] : ' ');
 
     pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
     refresh();

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH] fix curses update
  2010-04-20  9:38 [Qemu-devel] [PATCH] fix curses update Bernhard Kauer
@ 2010-04-22  1:27 ` andrzej zaborowski
  2010-04-22 14:08   ` Bernhard Kauer
  0 siblings, 1 reply; 7+ messages in thread
From: andrzej zaborowski @ 2010-04-22  1:27 UTC (permalink / raw)
  To: Bernhard Kauer; +Cc: qemu-devel

Hi,

On 20 April 2010 11:38, Bernhard Kauer <kauer@os.inf.tu-dresden.de> wrote:
> If a terminal is resized or the VGA model issues a full refresh, curses_update()
> is called, which uses mvwaddchnstr() to draw a full line of characters.  Unfortunatelly
> this routine expects a null-terminated string and early aborts if a null is present
> in the line.
>
> When booting an OS that zeros the VGA text buffer and later pokes single characters,
> the console output can become unreadable.  The attached patch corrects this bug.

I believe this issue has come up before with a similar patch but
someone checked their ncurses and they didn't see the same issue.  I
just checked and here mvwaddchnstr() does not expect a null-terminated
string either, but it skips the \0 characters.  So probably we should
replace them with spaces or something else,  I wouldn't like to
replace a single library call with 80 calls, it's better to go through
the string and replace them, maybe in console_write_ch or somewhere
else.

Cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH] fix curses update
  2010-04-22  1:27 ` andrzej zaborowski
@ 2010-04-22 14:08   ` Bernhard Kauer
  2010-05-03 18:06     ` Anthony Liguori
  0 siblings, 1 reply; 7+ messages in thread
From: Bernhard Kauer @ 2010-04-22 14:08 UTC (permalink / raw)
  To: andrzej zaborowski; +Cc: qemu-devel

Hi,

> I believe this issue has come up before with a similar patch but

well i've submitted such a patch more than two years ago.  Unfortunatelly
it got never applied, so that I have to patch my Qemu on every update...


> someone checked their ncurses and they didn't see the same issue. 
> I just checked and here mvwaddchnstr() does not expect a null-terminated
> string either, but it skips the \0 characters.

This is not conforming to the Single UNIX Specification, which states
that the string is shown "until a null chtype is encountered". See for
example:
  http://www.opengroup.org/onlinepubs/007908775/xcurses/addchstr.html 


>  So probably we should
> replace them with spaces or something else,  I wouldn't like to
> replace a single library call with 80 calls, it's better to go through
> the string and replace them, maybe in console_write_ch or somewhere
> else.

That would be a one-liner.  Should I send such a patch?


Thanks,

	Bernhard

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH] fix curses update
  2010-04-22 14:08   ` Bernhard Kauer
@ 2010-05-03 18:06     ` Anthony Liguori
  2010-05-20 20:53       ` [Qemu-devel] [PATCH] fix curses update - v2 Bernhard Kauer
  0 siblings, 1 reply; 7+ messages in thread
From: Anthony Liguori @ 2010-05-03 18:06 UTC (permalink / raw)
  To: Bernhard Kauer; +Cc: qemu-devel

On 04/22/2010 09:08 AM, Bernhard Kauer wrote:
> Hi,
>
>    
>> I believe this issue has come up before with a similar patch but
>>      
> well i've submitted such a patch more than two years ago.  Unfortunatelly
> it got never applied, so that I have to patch my Qemu on every update...
>
>
>    
>> someone checked their ncurses and they didn't see the same issue.
>> I just checked and here mvwaddchnstr() does not expect a null-terminated
>> string either, but it skips the \0 characters.
>>      
> This is not conforming to the Single UNIX Specification, which states
> that the string is shown "until a null chtype is encountered". See for
> example:
>    http://www.opengroup.org/onlinepubs/007908775/xcurses/addchstr.html
>
>
>    
>>   So probably we should
>> replace them with spaces or something else,  I wouldn't like to
>> replace a single library call with 80 calls, it's better to go through
>> the string and replace them, maybe in console_write_ch or somewhere
>> else.
>>      
> That would be a one-liner.  Should I send such a patch?
>    

Yes.

Regards,

Anthony Liguori

> Thanks,
>
> 	Bernhard
>
>
>
>    

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH] fix curses update - v2
  2010-05-03 18:06     ` Anthony Liguori
@ 2010-05-20 20:53       ` Bernhard Kauer
  2010-05-21 12:02         ` andrzej zaborowski
  0 siblings, 1 reply; 7+ messages in thread
From: Bernhard Kauer @ 2010-05-20 20:53 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

On Mon, May 03, 2010 at 01:06:46PM -0500, Anthony Liguori wrote:
> On 04/22/2010 09:08 AM, Bernhard Kauer wrote:
> >Hi,
> >
> >>I believe this issue has come up before with a similar patch but
> >well i've submitted such a patch more than two years ago.  Unfortunatelly
> >it got never applied, so that I have to patch my Qemu on every update...
> >
> >
> >>someone checked their ncurses and they didn't see the same issue.
> >>I just checked and here mvwaddchnstr() does not expect a null-terminated
> >>string either, but it skips the \0 characters.
> >This is not conforming to the Single UNIX Specification, which states
> >that the string is shown "until a null chtype is encountered". See for
> >example:
> >   http://www.opengroup.org/onlinepubs/007908775/xcurses/addchstr.html
> >
> >
> >>  So probably we should
> >>replace them with spaces or something else,  I wouldn't like to
> >>replace a single library call with 80 calls, it's better to go through
> >>the string and replace them, maybe in console_write_ch or somewhere
> >>else.
> >That would be a one-liner.  Should I send such a patch?
> 
> Yes.

Replace the \0 character with a space to allow to use mvwaddchnstr for
full-screen updates in curses mode.


Signed-off-by: Bernhard Kauer <kauer@tudos.org>

diff --git a/console.h b/console.h
index 6def115..42ff822 100644
--- a/console.h
+++ b/console.h
@@ -306,6 +306,7 @@ static inline int ds_get_bytes_per_pixel(DisplayState *ds)
 typedef unsigned long console_ch_t;
 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 {
+    if (!(ch & 0xff))  ch = 0x20;
     cpu_to_le32wu((uint32_t *) dest, ch);
 }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH] fix curses update - v2
  2010-05-20 20:53       ` [Qemu-devel] [PATCH] fix curses update - v2 Bernhard Kauer
@ 2010-05-21 12:02         ` andrzej zaborowski
  2010-05-21 12:43           ` Bernhard Kauer
  0 siblings, 1 reply; 7+ messages in thread
From: andrzej zaborowski @ 2010-05-21 12:02 UTC (permalink / raw)
  To: Bernhard Kauer; +Cc: qemu-devel

Hi,

I pushed a modified patch to preserve attributes such as background
colour.  Please check if this works for you.

Cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH] fix curses update - v2
  2010-05-21 12:02         ` andrzej zaborowski
@ 2010-05-21 12:43           ` Bernhard Kauer
  0 siblings, 0 replies; 7+ messages in thread
From: Bernhard Kauer @ 2010-05-21 12:43 UTC (permalink / raw)
  To: andrzej zaborowski; +Cc: qemu-devel

On Fri, May 21, 2010 at 02:02:43PM +0200, andrzej zaborowski wrote:
> I pushed a modified patch to preserve attributes such as background
> colour.

Good idea.

>  Please check if this works for you.

Yes, this works.


Thanks,

	Bernhard Kauer

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-05-21 12:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-20  9:38 [Qemu-devel] [PATCH] fix curses update Bernhard Kauer
2010-04-22  1:27 ` andrzej zaborowski
2010-04-22 14:08   ` Bernhard Kauer
2010-05-03 18:06     ` Anthony Liguori
2010-05-20 20:53       ` [Qemu-devel] [PATCH] fix curses update - v2 Bernhard Kauer
2010-05-21 12:02         ` andrzej zaborowski
2010-05-21 12:43           ` Bernhard Kauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).