Texinfo 4.0   Cygwin 20.1  GCC 2.95  PentiumII

After compiling texinfo 4.0 on Windows-NT under Cygwin 20.1 I found that makeinfo 
could not access any files.
After a gdb session I found the cause and a possible fix.

The code that was failing is in makeinfo/files.c.  The second 
execution of read() in the following loop was returning an
error.

find_and_load:172

  while ((n = read (file, result + count, file_size)) > 0)

I discovered that the failure occurred on second iteration because the buffer pointer 
passed to read() does did not
point to an area of memory big enough to contain "file_size" bytes.  The following 
patch corrects this problem by providing enough memory for the second read to succeed,
and return 0.  The other method would be to read one
byte at a time as is conditionally coded for WIN32, but
this patch should work on all platforms.  Some platforms
might possibly need a larger pad.

—-----------------------------------------------------------------------------------
*** files.c     Tue Mar 23 15:42:44 1999
--- files.c.patch       Tue Nov 30 10:29:25 1999
***************
*** 158,164 ****
      goto error_exit;
  
    /* Load the file, with enough room for a newline and a null. */
!   result = xmalloc (file_size + 2);
  
    /* VMS stat lies about the st_size value.  The actual number of
       readable bytes is always less than this value.  The arcane
--- 158,164 ----
      goto error_exit;
  
    /* Load the file, with enough room for a newline and a null. */
!   result = xmalloc (file_size*2 + 2);
  
    /* VMS stat lies about the st_size value.  The actual number of
       readable bytes is always less than this value.  The arcane
***************
*** 176,182 ****
  #endif /* WIN32 */
  #endif /* !VMS */
      count += n;
!   if (0 < count && count < file_size)
      result = xrealloc (result, count + 2); /* why waste the slack? */
    else if (n == -1)
  #else /* !VMS && !O_BINARY */
--- 176,182 ----
  #endif /* WIN32 */
  #endif /* !VMS */
      count += n;
!   if (0 < count && count < file_size*2)
      result = xrealloc (result, count + 2); /* why waste the slack? */
    else if (n == -1)
  #else /* !VMS && !O_BINARY */

Reply via email to