From: Bruno Haible Date: Wed, 5 Oct 2005 11:18:58 +0000 (+0000) Subject: Emit an error message when the msgids change through charset conversion. X-Git-Tag: v0.15~383 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bb50c194b072ce6af593c8756007eab3a837e85;p=thirdparty%2Fgettext.git Emit an error message when the msgids change through charset conversion. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 95b2ef936..17b2d9b3d 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,13 @@ +2005-10-01 Bruno Haible + + 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 * format.c: Include stdbool.h. diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index d0cc9d858..c125832a5 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -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 , 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. */ diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index ad44f0ce6..315a7124b 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -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 * diff --git a/gettext-tools/src/msgl-iconv.h b/gettext-tools/src/msgl-iconv.h index 6d4a361ee..e0f340cb0 100644 --- a/gettext-tools/src/msgl-iconv.h +++ b/gettext-tools/src/msgl-iconv.h @@ -19,6 +19,7 @@ #ifndef _MSGL_ICONV_H #define _MSGL_ICONV_H +#include #if HAVE_ICONV #include #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,