]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
makeinfo.c (find_and_load, [...]): Zero-terminate the file contents.
authorBruno Haible <haible@ilog.fr>
Tue, 2 Dec 1997 20:18:39 +0000 (21:18 +0100)
committerJeff Law <law@gcc.gnu.org>
Tue, 2 Dec 1997 20:18:39 +0000 (13:18 -0700)
        * makeinfo/makeinfo.c (find_and_load, convert_from_stream):
        Zero-terminate the file contents.

From-SVN: r16892

texinfo/ChangeLog
texinfo/makeinfo/makeinfo.c

index 7f5a278192ac245101555f497ceb047b0f62db20..2a65dd9198dc789ee762dc93b0a7f690e3d23225 100644 (file)
@@ -1,3 +1,8 @@
+Tue Dec  2 20:24:40 1997  Bruno Haible  <haible@ilog.fr>
+
+       * makeinfo/makeinfo.c (find_and_load, convert_from_stream):
+       Zero-terminate the file contents.
+
 Fri Oct 31 09:39:31 1997  Jeffrey A Law  (law@cygnus.com)
 
        * Makefile.in (install targets): Add a dummy target for sunos make.
index 2b9e966437653158d6ad68bb0a579830da5422ee..f51fe6fb23f3e8eb7c552ac8beaaf0136d02d649 100644 (file)
@@ -1,5 +1,5 @@
 /* Makeinfo -- convert texinfo format files into info files.
-   $Id: makeinfo.c,v 1.2 1997/09/03 04:25:24 law Exp $
+   $Id: makeinfo.c,v 1.3 1997/10/15 15:49:40 law Exp $
 
    Copyright (C) 1987, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
 
@@ -1167,7 +1167,7 @@ find_and_load (filename)
     goto error_exit;
 
   /* Load the file. */
-  result = (char *)xmalloc (1 + file_size);
+  result = (char *)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
@@ -1207,6 +1207,8 @@ find_and_load (filename)
      extra unnecessary work each time it is called (that is a lot of times).
      The SIZE_OF_INPUT_TEXT is one past the actual end of the text. */
   input_text[size_of_input_text] = '\n';
+  /* Necessary, because later on we call strlen(input_text+limit). */
+  input_text[size_of_input_text+1] = '\0';
   return (result);
 }
 
@@ -1947,21 +1949,22 @@ convert_from_stream (stream, name)
      FILE *stream;
      char *name;
 {
-  char *buffer = (char *)NULL;
-  int buffer_offset = 0, buffer_size = 0;
+  int buffer_size = READ_BUFFER_GROWTH;
+  char *buffer = (char *) xmalloc (buffer_size + 2);
+  int buffer_offset = 0;
 
   initialize_conversion ();
 
   /* Read until the end of the stream.  This isn't strictly correct, since
      the texinfo input may end before the stream ends, but it is a quick
-     working hueristic. */
+     working heuristic. */
   while (!feof (stream))
     {
       int count;
 
-      if (buffer_offset + (READ_BUFFER_GROWTH + 1) >= buffer_size)
+      if (buffer_offset + READ_BUFFER_GROWTH > buffer_size)
        buffer = (char *)
-         xrealloc (buffer, (buffer_size += READ_BUFFER_GROWTH));
+         xrealloc (buffer, (buffer_size += READ_BUFFER_GROWTH) + 2);
 
       count = fread (buffer + buffer_offset, 1, READ_BUFFER_GROWTH, stream);
 
@@ -1988,6 +1991,8 @@ convert_from_stream (stream, name)
      extra unnecessary work each time it is called (that is a lot of times).
      The SIZE_OF_INPUT_TEXT is one past the actual end of the text. */
   input_text[size_of_input_text] = '\n';
+  /* Necessary, because later on we call strlen(input_text+limit). */
+  input_text[size_of_input_text+1] = '\0';
 
   convert_from_loaded_file (name);
 }