www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/01/11/09:01:06

From: cgf AT cygnus DOT com (Christopher Faylor)
Subject: Re: fhandler_console bug
11 Jan 1999 09:01:06 -0800 :
Message-ID: <19990111115906.A19253.cygnus.cygwin32.developers@cygnus.com>
References: <179AA48D1741D211821700805FFE241873CAC7 AT HQMAIL02>
Mime-Version: 1.0
To: Kevin Schnitzius <kevins AT citrix DOT com>, cygwin32-developers AT cygnus DOT com

This is already the case in recent snapshots.  I don't know exactly
when it changed.

Snapshots are available from:

http://sourceware.cygnus.com/cygwin/snapshots/

On Mon, Jan 11, 1999 at 11:19:53AM -0500, Kevin Schnitzius wrote:
>While you are in fhandler_console.cc:
>
>@@ -1234,7 +1226,7 @@
>          else
>            buf[copied_chars++] = input_rec.Event.KeyEvent.uChar.AsciiChar;
>        }
>-      if (copied_chars ||
>+      if (copied_chars >= lenin ||
>          WaitForSingleObject (hndl, 0) != WAIT_OBJECT_0)
>        break;
>     }
>
>ReadConsoleInput() already blocks and there is no reason to wait if there
>are already characters read.  This patch fixes the problem where pasted
>characters fail to show up until a key is pressed.  It also fixes some
>console mode peculiarities where an extra key press is required.
>
>> -----Original Message-----
>> From: Christopher Faylor [mailto:cgf AT cygnus DOT com]
>> Sent: Monday, January 11, 1999 9:18 AM
>> To: Kazuhiro Fujieda; cygwin32-developers AT cygnus DOT com
>> Subject: Re: fhandler_console bug
>> 
>> 
>> I've added code to fhandler_console.cc which specifically handles EOF.
>> It will be in the next snapshot.
>> 
>> Thanks for finding this.
>> 
>> -chris
>> 
>> On Mon, Jan 11, 1999 at 09:16:00PM +0900, Kazuhiro Fujieda wrote:
>> >The following program is hanged up when Return and ^Z are typed
>> >continuously in notty mode on Win95.
>> >
>> >#include <stdio.h>
>> >main()
>> >{
>> >    int ch;
>> >    while ((ch = fgetc(stdin)) != EOF) {
>> >	printf("ch = %02x\n", ch);
>> >    }
>> >}
>> >
>> >The reason of it is in fhandler_console.cc:1143-1157.
>> >
>> >1142:	  copied_chars = 0x12345678;
>> >1143:	  if ((res = ReadFile (hndl, buf, lenin, 
>> &copied_chars, NULL)) &&
>> >1144:	      copied_chars == 0x12345678)
>> >
>> >When ^Z is typed, ReadFile catch the EOF and set copied_char is 0.
>> >But the succeeding code take no account of this case.  On Win95,
>> >ReadFile doesn't modify the contents of buf in this case, so
>> >buf[0] is still '\n' and the program is crushed by the following
>> >code.
>> >
>> >1153:	  if (!looped++ && buf[0] == '\n')
>> >1154:	    {
>> >1155:	      if (!--copied_chars)
>> >1156:		continue;
>> >1157:	      memcpy (buf, buf + 1, copied_chars);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019