BUG: _read() Returns -1 When Reading Last Byte of a Segment

ID: Q120153

1.00 1.50 WINDOWS kbprg kbbuglist

The information in this article applies to:

SYMPTOMS

If you open a file with _open() specifying O_TEXT mode or letting it default to O_TEXT mode and then you call _read() to read to the last byte of a segment, the _read() function returns -1. Though this return value indicates that an error occurred, the information was read correctly.

CAUSE

The carry flag is unexpectedly set when looking for carriage return, line feed (CR/LF) pairs at 0xFFFF. The Run-Time incorrectly interprets this as an error and returns -1 instead of the number of characters read.

STATUS

Microsoft has confirmed this to be a bug in the products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following sample code illustrates the problem:

Sample Code

/* Compile options needed: /AL
*/ 

   #include <stdio.h>
   #include <fcntl.h>
   #include <sys\types.h>
   #include <sys\stat.h>
   #include <malloc.h>
   #include <io.h>
   #include <dos.h>
   #include <errno.h>

   int hfIn;
   int ret_val;
   char huge* lpcBase;
   char huge* lpcTest;

   void main(void)
   {
      lpcBase = (char _huge*) halloc(100000L, 1);
      lpcTest= lpcBase;
      FP_OFF(lpcTest)= 0xFFFC;   // Point to end of the segment.

      hfIn = open("C:\\config.sys", _O_RDONLY);
      ret_val = read(hfIn, lpcTest, 4);
      if (ret_val< 0)
      {
         printf ("ret_val = %i indicating Failure Reading to 0xFFFF\n",
                  ret_val);
         printf ("errno = %d\n", errno);
      }
      close(hfIn);
   }

Additional reference words: 6.00 6.00a 6.00ax 7.00 7.00a 1.00 1.50 KBCategory: kbprg kbbuglist KBSubcategory: CRTIss Keywords : kb16bitonly

Last Reviewed: July 23, 1997