]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
More reliable checking for read errors.
authorBruno Haible <bruno@clisp.org>
Fri, 19 Sep 2003 08:32:51 +0000 (08:32 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:00 +0000 (12:11 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/po-lex.c
gettext-tools/src/x-rst.c

index 8fa8b8472f972c9b9520f71ae16a862ce314f83d..77d2859c1e2c9f9cc406aaced1b8bf0005bc6e21 100644 (file)
@@ -1,3 +1,12 @@
+2003-09-14  Bruno Haible  <bruno@clisp.org>
+
+       More reliable checking for read errors.
+       * po-lex.c (mbfile_getc): Diagnose read errors also in the middle of
+       multibyte characters.
+       (lex_getc): Diagnose read errors also right after backslash.
+       * x-rst.c (extract_rst): Diagnose read errors also inside ConstName
+       and immediately after #.
+
 2003-09-14  Bruno Haible  <bruno@clisp.org>
 
        * write-mo.c: Include fwriterror.h.
        * user-email.in: Use 'gettext' instead of @PACKAGE@.
 
 
-See ChangeLog.0 for earlier changes.
+See ChangeLog.0 for earlier changes.
\ No newline at end of file
index 9564e2b2964c706f66aa2da46ced6229a0a18af1..afc8ac6cd770f6d16e8e3272c00875911e50fed9 100644 (file)
@@ -389,6 +389,8 @@ mbfile_init (mbfile_t mbf, FILE *stream)
   mbf->bufcount = 0;
 }
 
+/* Read the next multibyte character from mbf and put it into mbc.
+   If a read error occurs, errno is set and ferror (mbf->fp) becomes true.  */
 static void
 mbfile_getc (mbchar_t mbc, mbfile_t mbf)
 {
@@ -478,6 +480,8 @@ mbfile_getc (mbchar_t mbc, mbfile_t mbf)
                  if (c == EOF)
                    {
                      mbf->eof_seen = true;
+                     if (ferror (mbf->fp))
+                       goto eof;
                      if (signal_eilseq)
                        po_gram_error (_("\
 incomplete multibyte sequence at end of file"));
@@ -535,7 +539,15 @@ incomplete multibyte sequence at end of line"));
            {
              /* Read one more byte.  */
              int c = getc (mbf->fp);
-             if (c != EOF)
+             if (c == EOF)
+               {
+                 if (ferror (mbf->fp))
+                   {
+                     mbf->eof_seen = true;
+                     goto eof;
+                   }
+               }
+             else
                {
                  mbf->buf[1] = (unsigned char) c;
                  mbf->bufcount++;
@@ -649,8 +661,11 @@ lex_getc (mbchar_t mbc)
       if (mb_iseof (mbc))
        {
          if (ferror (mbf->fp))
-           error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
-                  gram_pos.file_name);
+           {
+           bomb:
+             error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
+                    gram_pos.file_name);
+           }
          break;
        }
 
@@ -669,10 +684,16 @@ lex_getc (mbchar_t mbc)
 
          mbfile_getc (mbc2, mbf);
 
+         if (mb_iseof (mbc2))
+           {
+             if (ferror (mbf->fp))
+               goto bomb;
+             break;
+           }
+
          if (!mb_iseq (mbc2, '\n'))
            {
-             if (!mb_iseof (mbc2))
-               mbfile_ungetc (mbc2, mbf);
+             mbfile_ungetc (mbc2, mbf);
              break;
            }
 
index 15aa4fbcb3b221b1dad46fa40e6c7a85187de97b..15bf6b501bfe55eea01b74029dfd9cf612e5ae50 100644 (file)
@@ -116,6 +116,8 @@ extract_rst (FILE *f,
            break;
          buffer[bufpos++] = c;
          c = getc (f);
+         if (c == EOF && ferror (f))
+           goto bomb;
        }
       buffer[bufpos] = '\0';
       location = xstrdup (buffer);
@@ -160,6 +162,8 @@ extract_rst (FILE *f,
            {
              int n;
              c = getc (f);
+             if (c == EOF && ferror (f))
+               goto bomb;
              if (c == EOF || !isdigit (c))
                {
                  error_with_progname = false;
@@ -222,6 +226,9 @@ extract_rst (FILE *f,
     }
 
   if (ferror (f))
-    error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
-          real_filename);
+    {
+    bomb:
+      error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
+            real_filename);
+    }
 }