]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Emit an error message when the msgids change through charset conversion.
authorBruno Haible <bruno@clisp.org>
Wed, 5 Oct 2005 11:18:58 +0000 (11:18 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:52 +0000 (12:12 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/msgl-cat.c
gettext-tools/src/msgl-iconv.c
gettext-tools/src/msgl-iconv.h

index 95b2ef9365d6717eb1104977e5798f6ee2fb262b..17b2d9b3d5f24f1975817b316a763a0ae0e9ffca 100644 (file)
@@ -1,3 +1,13 @@
+2005-10-01  Bruno Haible  <bruno@clisp.org>
+
+       Avoid a crash when msgcat or msgconv is asked to convert a non-ASCII
+       msgid.
+       * msgl-iconv.h (iconv_message_list): Change return type to boolean.
+       * msgl-iconv.c (iconv_message_list): Likewise. Return true if some
+       msgids change.
+       * msgl-cat.c (catenate_msgdomain_list): Exit with an error message if
+       the msgids change through charset conversion.
+
 2005-10-04  Bruno Haible  <bruno@clisp.org>
 
        * format.c: Include stdbool.h.
index d0cc9d858dd06d01cf0b45bcaed088e33658300c..c125832a5cd7b3954f81360acc25f076ec1efdad 100644 (file)
@@ -1,5 +1,5 @@
 /* Message list concatenation and duplicate handling.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -470,8 +470,20 @@ To select a different output encoding, use the --to-code option.\n\
               conversion that would only replace the charset name in the
               header entry with its canonical equivalent.  */
            if (!(to_code == NULL && canon_charsets[n][k] == canon_to_code))
-             iconv_message_list (mdlp->item[k]->messages, canon_charsets[n][k],
-                                 canon_to_code, files[n]);
+             if (iconv_message_list (mdlp->item[k]->messages,
+                                     canon_charsets[n][k], canon_to_code,
+                                     files[n]))
+               {
+                 multiline_error (xstrdup (""),
+                                  xasprintf (_("\
+Conversion of file %s from %s encoding to %s encoding\n\
+changes some msgids.\n\
+Either change all msgids to be pure ASCII, or ensure they are\n\
+UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
+                                             files[n], canon_charsets[n][k],
+                                             canon_to_code));
+                 exit (EXIT_FAILURE);
+               }
       }
 
   /* Fill the resulting messages.  */
index ad44f0ce64715c65133c37417c5777b0ccfcc65c..315a7124b79f91389eea937034c4aa0b63268c73 100644 (file)
@@ -275,17 +275,18 @@ convert_msgstr (iconv_t cd, message_ty *mp,
 #endif
 
 
-void
+bool
 iconv_message_list (message_list_ty *mlp,
                    const char *canon_from_code, const char *canon_to_code,
                    const char *from_filename)
 {
   bool canon_from_code_overridden = (canon_from_code != NULL);
+  bool msgids_changed;
   size_t j;
 
   /* If the list is empty, nothing to do.  */
   if (mlp->nitems == 0)
-    return;
+    return false;
 
   /* Search the header entry, and extract and replace the charset name.  */
   for (j = 0; j < mlp->nitems; j++)
@@ -369,13 +370,14 @@ two different charsets \"%s\" and \"%s\" in input file"),
 input file doesn't contain a header entry with a charset specification"));
     }
 
+  msgids_changed = false;
+
   /* If the two encodings are the same, nothing to do.  */
   if (canon_from_code != canon_to_code)
     {
 #if HAVE_ICONV
       iconv_t cd;
       struct conversion_context context;
-      bool msgids_changed;
 
       /* Avoid glibc-2.1 bug with EUC-KR.  */
 # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION
@@ -396,7 +398,6 @@ and iconv() does not support this conversion."),
       context.to_code = canon_to_code;
       context.from_filename = from_filename;
 
-      msgids_changed = false;
       for (j = 0; j < mlp->nitems; j++)
        {
          message_ty *mp = mlp->item[j];
@@ -428,6 +429,8 @@ This version was built without iconv()."),
                                basename (program_name));
 #endif
     }
+
+  return msgids_changed;
 }
 
 msgdomain_list_ty *
index 6d4a361ee0e96fe707852c5986ae66661eeed4ff..e0f340cb03e7339589800c52fc0674f6323009fa 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef _MSGL_ICONV_H
 #define _MSGL_ICONV_H
 
+#include <stdbool.h>
 #if HAVE_ICONV
 #include <iconv.h>
 #endif
@@ -51,8 +52,9 @@ extern char *convert_string (iconv_t cd, const char *string,
 /* Converts the message list MLP to the (already canonicalized) encoding
    CANON_TO_CODE.  The (already canonicalized) encoding before conversion
    can be passed as CANON_FROM_CODE; if NULL is passed instead, the
-   encoding is looked up in the header entry.  */
-extern void
+   encoding is looked up in the header entry.  Returns true if and only if
+   some msgid changed due to the conversion.  */
+extern bool
        iconv_message_list (message_list_ty *mlp,
                           const char *canon_from_code,
                           const char *canon_to_code,