+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.
/* 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
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. */
#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++)
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
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];
basename (program_name));
#endif
}
+
+ return msgids_changed;
}
msgdomain_list_ty *
#ifndef _MSGL_ICONV_H
#define _MSGL_ICONV_H
+#include <stdbool.h>
#if HAVE_ICONV
#include <iconv.h>
#endif
/* 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,