Mail Archives: cygwin-developers/1999/01/11/06:31:38
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);
>____
> | AIST Kazuhiro Fujieda <fujieda AT jaist DOT ac DOT jp>
> | HOKURIKU School of Information Science
>o_/ 1990 Japan Advanced Institute of Science and Technology
>
--
cgf AT cygnus DOT com
http://www.cygnus.com/
- Raw text -