Mail Archives: cygwin-developers/1999/01/11/04:31:07

From: fujieda AT jaist DOT ac DOT jp (Kazuhiro Fujieda)
Subject: fhandler_console bug
11 Jan 1999 04:31:07 -0800 :
Message-ID: <>
Mime-Version: 1.0 (generated by SEMI MIME-Edit 0.100 - "Shijima")
To: cygwin32-developers AT cygnus DOT com

The following program is hanged up when Return and ^Z are typed
continuously in notty mode on Win95.

#include <stdio.h>
    int ch;
    while ((ch = fgetc(stdin)) != EOF) {
	printf("ch = %02x\n", ch);

The reason of it is in

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

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

- Raw text -

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