]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New macros XMALLOC, XNMALLOC.
authorBruno Haible <bruno@clisp.org>
Mon, 6 Nov 2006 20:15:10 +0000 (20:15 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:19 +0000 (12:14 +0200)
74 files changed:
gettext-runtime/src/ChangeLog
gettext-runtime/src/envsubst.c
gettext-runtime/src/gettext.c
gettext-runtime/src/ngettext.c
gettext-tools/libgettextpo/ChangeLog
gettext-tools/libgettextpo/gettext-po.c
gettext-tools/libgrep/ChangeLog
gettext-tools/libgrep/m-common.c
gettext-tools/libgrep/m-fgrep.c
gettext-tools/libgrep/m-regex.c
gettext-tools/src/ChangeLog
gettext-tools/src/filter-sr-latin.c
gettext-tools/src/format-awk.c
gettext-tools/src/format-boost.c
gettext-tools/src/format-c.c
gettext-tools/src/format-csharp.c
gettext-tools/src/format-elisp.c
gettext-tools/src/format-gcc-internal.c
gettext-tools/src/format-java.c
gettext-tools/src/format-librep.c
gettext-tools/src/format-lisp.c
gettext-tools/src/format-pascal.c
gettext-tools/src/format-perl-brace.c
gettext-tools/src/format-perl.c
gettext-tools/src/format-php.c
gettext-tools/src/format-python.c
gettext-tools/src/format-qt.c
gettext-tools/src/format-scheme.c
gettext-tools/src/format-sh.c
gettext-tools/src/format-tcl.c
gettext-tools/src/format-ycp.c
gettext-tools/src/message.c
gettext-tools/src/msgexec.c
gettext-tools/src/msgfilter.c
gettext-tools/src/msgfmt.c
gettext-tools/src/msginit.c
gettext-tools/src/msgl-cat.c
gettext-tools/src/msgl-check.c
gettext-tools/src/msgl-english.c
gettext-tools/src/msgl-fsearch.c
gettext-tools/src/msgl-iconv.c
gettext-tools/src/msgmerge.c
gettext-tools/src/po-gram-gen.y
gettext-tools/src/read-catalog-abstract.c
gettext-tools/src/read-mo.c
gettext-tools/src/read-properties.c
gettext-tools/src/read-stringtable.c
gettext-tools/src/str-list.c
gettext-tools/src/write-csharp.c
gettext-tools/src/write-java.c
gettext-tools/src/write-mo.c
gettext-tools/src/write-po.c
gettext-tools/src/write-properties.c
gettext-tools/src/write-qt.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-perl.c
gettext-tools/src/x-po.c
gettext-tools/src/x-python.c
gettext-tools/src/x-scheme.c
gettext-tools/src/x-sh.c
gettext-tools/src/x-smalltalk.c
gettext-tools/src/x-tcl.c
gettext-tools/src/xgettext.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/tstgettext.c
gnulib-local/ChangeLog
gnulib-local/lib/fstrcmp.c
gnulib-local/lib/hash.c
gnulib-local/lib/propername.c
gnulib-local/lib/xalloc.h
gnulib-local/lib/xgetcwd.c
gnulib-local/lib/xstrdup.c

index bb52aefb9259cebea2dd8614d1c477795afc696c..426cd959f479019f2fc738810448d0836be76962 100644 (file)
@@ -1,3 +1,10 @@
+2006-11-03  Bruno Haible  <bruno@clisp.org>
+
+       Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
+       * envsubst.c (note_variable): Use XNMALLOC instead of xmalloc.
+       * gettext.c (expand_escape): Likewise.
+       * ngettext.c (expand_escape): Likewise.
+
 2006-10-26  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.16 released.
index c851267578754d763b0df686b06a9532bc8e4d86..65f73098e21bd9bbeab5046127845c57c8f9b8c7 100644 (file)
@@ -411,7 +411,7 @@ static string_list_ty variables_set;
 static void
 note_variable (const char *var_ptr, size_t var_len)
 {
-  char *string = (char *) xmalloc (var_len + 1);
+  char *string = XNMALLOC (var_len + 1, char);
   memcpy (string, var_ptr, var_len);
   string[var_len] = '\0';
 
index bea3f5aececd8e4b92e27c860a9b5179bebdee79..a49165892d6b22610827c6cc224d6cd4dc9ece0c 100644 (file)
@@ -301,7 +301,7 @@ expand_escape (const char *str)
       ++cp;
     }
 
-  retval = (char *) xmalloc (strlen (str));
+  retval = XNMALLOC (strlen (str), char);
 
   rp = retval + (cp - str);
   memcpy (retval, str, cp - str);
index be021c920460d6599317eadf1497c5c0a0ef7000..af5c5f20e5c6d61d984e656bb787ae6343be2144 100644 (file)
@@ -267,7 +267,7 @@ expand_escape (const char *str)
       ++cp;
     }
 
-  retval = (char *) xmalloc (strlen (str));
+  retval = XNMALLOC (strlen (str), char);
 
   rp = retval + (cp - str);
   memcpy (retval, str, cp - str);
index dc0e3529d21017192210f01b4eda2ac295f2dd42..9ae3c271d55991076288d88afcd48e69e32fb411 100644 (file)
@@ -1,3 +1,12 @@
+2006-11-03  Bruno Haible  <bruno@clisp.org>
+
+       Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
+       * gettext-po.c (po_file_create, po_file_read): Use XMALLOC instead of
+       xmalloc.
+       (po_file_domains, po_header_field, po_header_set_field): Use XNMALLOC
+       instead of xmalloc.
+       (po_message_iterator: Use XMALLOC instead of xmalloc.
+
 2006-10-29  Bruno Haible  <bruno@clisp.org>
 
        Don't name mangle exported symbols in C++ mode.
index 2a139aef96fe78e71bfef57b18e5ffbb05524766..87df81b85f0ce7eaf837f1a50804fe49c1875da4 100644 (file)
@@ -80,7 +80,7 @@ po_file_create (void)
 {
   po_file_t file;
 
-  file = (struct po_file *) xmalloc (sizeof (struct po_file));
+  file = XMALLOC (struct po_file);
   file->mdlp = msgdomain_list_alloc (false);
   file->real_filename = _("<unnamed>");
   file->logical_filename = file->real_filename;
@@ -119,7 +119,7 @@ po_file_read (const char *filename, po_xerror_handler_t handler)
     handler->xerror2;
   gram_max_allowed_errors = UINT_MAX;
 
-  file = (struct po_file *) xmalloc (sizeof (struct po_file));
+  file = XMALLOC (struct po_file);
   file->real_filename = filename;
   file->logical_filename = filename;
   file->mdlp = read_catalog_stream (fp, file->real_filename,
@@ -165,7 +165,7 @@ po_file_read_v2 (const char *filename, po_error_handler_t handler)
   po_multiline_error   = handler->multiline_error;
   gram_max_allowed_errors = UINT_MAX;
 
-  file = (struct po_file *) xmalloc (sizeof (struct po_file));
+  file = XMALLOC (struct po_file);
   file->real_filename = filename;
   file->logical_filename = filename;
   file->mdlp = read_catalog_stream (fp, file->real_filename,
@@ -206,7 +206,7 @@ po_file_read (const char *filename)
        return NULL;
     }
 
-  file = (struct po_file *) xmalloc (sizeof (struct po_file));
+  file = XMALLOC (struct po_file);
   file->real_filename = filename;
   file->logical_filename = filename;
   file->mdlp = read_catalog_stream (fp, file->real_filename,
@@ -288,8 +288,7 @@ po_file_domains (po_file_t file)
   if (file->domains == NULL)
     {
       size_t n = file->mdlp->nitems;
-      const char **domains =
-       (const char **) xmalloc ((n + 1) * sizeof (const char *));
+      const char **domains = XNMALLOC (n + 1, const char *);
       size_t j;
 
       for (j = 0; j < n; j++)
@@ -355,7 +354,7 @@ po_header_field (const char *header, const char *field)
          if (value_end == NULL)
            value_end = value_start + strlen (value_start);
 
-         value = (char *) xmalloc (value_end - value_start + 1);
+         value = XNMALLOC (value_end - value_start + 1, char);
          memcpy (value, value_start, value_end - value_start);
          value[value_end - value_start] = '\0';
 
@@ -410,7 +409,7 @@ po_header_set_field (const char *header, const char *field, const char *value)
            header_part3_len = header + header_len - oldvalue_end;
            result_len = header_part1_len + value_len + header_part3_len;
                    /* = header_len - oldvalue_len + value_len */
-           result = (char *) xmalloc (result_len + 1);
+           result = XNMALLOC (result_len + 1, char);
            memcpy (result, header, header_part1_len);
            memcpy (result + header_part1_len, value, value_len);
            memcpy (result + header_part1_len + value_len, oldvalue_end,
@@ -434,7 +433,7 @@ po_header_set_field (const char *header, const char *field, const char *value)
 
     newline = (header_len > 0 && header[header_len - 1] != '\n' ? 1 : 0);
     result_len = header_len + newline + field_len + 2 + value_len + 1;
-    result = (char *) xmalloc (result_len + 1);
+    result = XNMALLOC (result_len + 1, char);
     memcpy (result, header, header_len);
     if (newline)
       *(result + header_len) = '\n';
@@ -461,9 +460,7 @@ po_message_iterator (po_file_t file, const char *domain)
   if (domain == NULL)
     domain = MESSAGE_DOMAIN_DEFAULT;
 
-  iterator =
-    (struct po_message_iterator *)
-    xmalloc (sizeof (struct po_message_iterator));
+  iterator = XMALLOC (struct po_message_iterator);
   iterator->file = file;
   iterator->domain = xstrdup (domain);
   iterator->mlp = msgdomain_list_sublist (file->mdlp, domain, false);
index d117aa32a468bbe1c57907cfaa68948ac4c35038..46c8907f7388972b510826fab680abe065b68bf0 100644 (file)
@@ -1,3 +1,11 @@
+2006-11-03  Bruno Haible  <bruno@clisp.org>
+
+       Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
+       * m-common.c (kwsinit): Use XNMALLOC instead of xmalloc.
+       * m-fgrep.c (Fcompile): Use XMALLOC instead of xmalloc.
+       * m-regex.c (Gcompile, compile): Use XMALLOC, XNMALLOC instead of
+       xmalloc.
+
 2006-11-01  Bruno Haible  <bruno@clisp.org>
 
        * dfa.c (delete_pos): Renamed from remove.
index 3bf13a6cddb1485475d4e12b52e80d5c303dd6a6..1bf9e3955ce654bf94b16f42bc75eb5dd9b995f7 100644 (file)
@@ -1,5 +1,5 @@
 /* Pattern Matchers - Common Utilities.
-   Copyright (C) 1992, 1998, 2000, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1998, 2000, 2005-2006 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -48,7 +48,7 @@ kwsinit (struct compiled_kwset *ckwset,
     {
       int i;
 
-      ckwset->trans = (char *) xmalloc (NCHAR * sizeof (char));
+      ckwset->trans = XNMALLOC (NCHAR, char);
       for (i = 0; i < NCHAR; i++)
        ckwset->trans[i] = TOLOWER (i);
       ckwset->kwset = kwsalloc (ckwset->trans);
index 305b997ac6ced81d2d2f0c29f0f6df8672ff614e..7aa86ed25221f3b526ca278b7398577898920bcc 100644 (file)
@@ -46,7 +46,7 @@ Fcompile (const char *pattern, size_t pattern_size,
   struct compiled_kwset *ckwset;
   const char *beg, *lim, *err;
 
-  ckwset = (struct compiled_kwset *) xmalloc (sizeof (struct compiled_kwset));
+  ckwset = XMALLOC (struct compiled_kwset);
   kwsinit (ckwset, match_icase, match_words, match_lines, eolbyte);
 
   beg = pattern;
index a53c96f4f43795dd751bad595f4c743e854b3e51..b802a12a664ceb9f1238836a8f09b17a88265d94 100644 (file)
@@ -127,7 +127,7 @@ Gcompile (const char *pattern, size_t pattern_size,
   size_t total = pattern_size;
   const char *motif = pattern;
 
-  cregex = (struct compiled_regex *) xmalloc (sizeof (struct compiled_regex));
+  cregex = XMALLOC (struct compiled_regex);
   memset (cregex, '\0', sizeof (struct compiled_regex));
   cregex->match_words = match_words;
   cregex->match_lines = match_lines;
@@ -184,7 +184,7 @@ Gcompile (const char *pattern, size_t pattern_size,
       static const char line_end[] = "\\)$";
       static const char word_beg[] = "\\(^\\|[^[:alnum:]_]\\)\\(";
       static const char word_end[] = "\\)\\([^[:alnum:]_]\\|$\\)";
-      char *n = (char *) xmalloc (sizeof word_beg - 1 + pattern_size + sizeof word_end);
+      char *n = XNMALLOC (sizeof word_beg - 1 + pattern_size + sizeof word_end, char);
       size_t i;
       strcpy (n, match_lines ? line_beg : word_beg);
       i = strlen (n);
@@ -213,7 +213,7 @@ compile (const char *pattern, size_t pattern_size,
   size_t total = pattern_size;
   const char *motif = pattern;
 
-  cregex = (struct compiled_regex *) xmalloc (sizeof (struct compiled_regex));
+  cregex = XMALLOC (struct compiled_regex);
   memset (cregex, '\0', sizeof (struct compiled_regex));
   cregex->match_words = match_words;
   cregex->match_lines = match_lines;
@@ -270,7 +270,7 @@ compile (const char *pattern, size_t pattern_size,
       static const char line_end[] = ")$";
       static const char word_beg[] = "(^|[^[:alnum:]_])(";
       static const char word_end[] = ")([^[:alnum:]_]|$)";
-      char *n = (char *) xmalloc (sizeof word_beg - 1 + pattern_size + sizeof word_end);
+      char *n = XNMALLOC (sizeof word_beg - 1 + pattern_size + sizeof word_end, char);
       size_t i;
       strcpy (n, match_lines ? line_beg : word_beg);
       i = strlen(n);
index 537ecab8aaaebcc0b26a92adf95e4496c3cf7474..18ff3120d45d6848a81815fa6d73a3dee5b5005f 100644 (file)
@@ -1,3 +1,116 @@
+2006-11-03  Bruno Haible  <bruno@clisp.org>
+
+       Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
+       * filter-sr-latin.c (serbian_to_latin): Use XNMALLOC instead of xmalloc.
+       * format-awk.c (format_parse): Use XMALLOC instead of xmalloc.
+       * format-boost.c (format_parse): Likewise.
+       * format-c.c (format_parse): Use XMALLOC, XNMALLOC instead of xmalloc.
+       (get_sysdep_c_format_directives): Use XNMALLOC instead of xmalloc.
+       * format-csharp.c (format_parse): Use XMALLOC instead of xmalloc.
+       * format-elisp.c (format_parse): Likewise.
+       * format-gcc-internal.c (format_parse): Likewise.
+       * format-java.c (format_parse): Likewise.
+       * format-librep.c (format_parse): Likewise.
+       * format-lisp.c (copy_list): Use XMALLOC, XNMALLOC instead of xmalloc.
+       (make_unconstrained_list): Likewise.
+       (make_empty_list): Use XMALLOC instead of xmalloc.
+       (rotate_loop): Use XNMALLOC instead of xmalloc.
+       (make_intersected_list): Use XMALLOC instead of xmalloc.
+       (make_union_list): Use XMALLOC, XNMALLOC instead of xmalloc.
+       (make_repeated_list_of_lists): Likewise.
+       (make_repeated_list): Likewise.
+       (format_parse): Use XMALLOC instead of xmalloc.
+       * format-pascal.c (format_parse): Likewise.
+       * format-perl.c (format_parse): Likewise.
+       * format-perl-brace.c (format_parse): Use XMALLOC, XNMALLOC instead of
+       xmalloc.
+       * format-php.c (format_parse): Use XMALLOC instead of xmalloc.
+       * format-python.c (format_parse): Use XMALLOC, XNMALLOC instead of
+       xmalloc.
+       * format-qt.c (format_parse): Use XMALLOC instead of xmalloc.
+       * format-scheme.c (copy_list): Use XMALLOC, XNMALLOC instead of xmalloc.
+       (make_unconstrained_list): Likewise.
+       (make_empty_list): Use XMALLOC instead of xmalloc.
+       (rotate_loop): Use XNMALLOC instead of xmalloc.
+       (make_intersected_list): Use XMALLOC instead of xmalloc.
+       (make_union_list): Use XMALLOC, XNMALLOC instead of xmalloc.
+       (make_repeated_list_of_lists): Likewise.
+       (make_repeated_list): Likewise.
+       (format_parse): Use XMALLOC instead of xmalloc.
+       * format-sh.c (format_parse): Use XMALLOC, XNMALLOC instead of xmalloc.
+       * format-tcl.c (format_parse): Use XMALLOC instead of xmalloc.
+       * format-ycp.c (format_parse): Likewise.
+       * message.c (message_alloc, message_list_list_alloc, msgdomain_alloc):
+       Use XMALLOC instead of xmalloc.
+       (msgdomain_list_alloc): Use XMALLOC, XNMALLOC instead of xmalloc.
+       * msgexec.c (main): Use XNMALLOC instead of xmalloc.
+       * msgfilter.c (main, generic_filter, process_message): Likewise.
+       * msgfmt.c (add_mo_suffix): Likewise.
+       (new_domain): Use XMALLOC instead of xmalloc.
+       * msginit.c (catalogname_for_locale, language_of_locale,
+       get_user_fullname, get_field, put_field, subst_string,
+       update_msgstr_plurals): Use XNMALLOC instead of xmalloc.
+       * msgl-cat.c (catenate_msgdomain_list): Likewise.
+       * msgl-check.c (check_plural_eval): Use XCALLOC instead of xcalloc.
+       * msgl-english.c (msgdomain_list_english): Use XNMALLOC instead of
+       xmalloc.
+       * msgl-fsearch.c (new_index): Likewise.
+       (message_fuzzy_index_alloc): Use XMALLOC instead of xmalloc.
+       (mult_index_list_accumulate): Use XNMALLOC instead of xmalloc.
+       * msgl-iconv.c (iconv_message_list): Likewise.
+       * msgmerge.c (message_merge, match_domain): Likewise.
+       * po-gram-gen.y (plural_form_list): Likewise.
+       * read-catalog-abstract.c (po_parse_comment_filepos,
+       po_parse_comment_solaris_filepos): Likewise.
+       * read-mo.c (get_sysdep_string): Likewise.
+       * read-properties.c (conv_from_iso_8859_1, read_escaped_string):
+       Likewise.
+       * read-stringtable.c (conv_from_ucs4): Likewise.
+       * str-list.c (string_list_alloc): Use XMALLOC instead of xmalloc.
+       (string_list_concat, string_list_join): Use XNMALLOC instead of xmalloc.
+       * write-csharp.c (construct_class_name, msgdomain_write_csharp):
+       Likewise.
+       * write-java.c (compute_hashsize, compute_table_items): Likewise.
+       * write-mo.c: Include xsize.h.
+       (write_table): Use XNMALLOC instead of xmalloc. Use xsum, xtimes in
+       xmalloc argument.
+       * write-po.c (wrap): Use XNMALLOC instead of xmalloc.
+       * write-properties.c (conv_to_java): Likewise.
+       * write-qt.c (conv_to_iso_8859_1, conv_to_utf16): Likewise.
+       * x-elisp.c (init_token, string_of_object): Likewise.
+       (read_object): Use XMALLOC instead of xmalloc.
+       * x-librep.c (init_token, string_of_object): Use XNMALLOC instead of
+       xmalloc.
+       (read_object): Use XMALLOC instead of xmalloc.
+       * x-lisp.c (x_lisp_keyword, init_token, string_of_object): Use XNMALLOC
+       instead of xmalloc.
+       (read_object): Use XMALLOC instead of xmalloc.
+       * x-perl.c (get_here_document, extract_quotelike_pass1,
+       extract_quotelike_pass3): Use XNMALLOC instead of xmalloc.
+       (x_perl_lex): Use XMALLOC instead of xmalloc.
+       * x-po.c (strextract_add_message, extract): Use XNMALLOC instead of
+       xmalloc.
+       * x-python.c (try_to_extract_coding): Use XNMALLOC instead of xmalloc.
+       * x-scheme.c (init_token, string_of_object): Use XNMALLOC
+       instead of xmalloc.
+       (read_object): Use XMALLOC instead of xmalloc.
+       * x-sh.c (init_token, string_of_token, string_of_word): Use XNMALLOC
+       instead of xmalloc.
+       (read_word): Use XMALLOC instead of xmalloc.
+       * x-smalltalk.c (phase2_get): Use XNMALLOC instead of xmalloc.
+       * x-tcl.c (init_token, string_of_word): Use XNMALLOC instead of xmalloc.
+       (read_word): Use XMALLOC instead of xmalloc.
+       * xgettext.c: Include xsize.h.
+       (split_keywordspec): Use XNMALLOC instead of xmalloc.
+       (insert_keyword_callshape): Use XMALLOC instead of xmalloc. Use xsum,
+       xtimes to avoid overflow.
+       (flag_context_list_table_insert): Use XMALLOC instead of xmalloc.
+       (savable_comment_add): Likewise.
+       (remember_a_message_plural): Use XNMALLOC instead of xmalloc.
+       (arglist_parser_alloc, arglist_parser_clone): Use xsum, xtimes.
+       (arglist_parser_done): Use XNMALLOC instead of xmalloc.
+       (finalize_header): Likewise.
+
 2006-10-30  Bruno Haible  <bruno@clisp.org>
 
        * plural-eval.h [C++]: Define functions without name mangling.
index 0af560e6fe66893bc7bf987801b4b800bcfea00d..7fa2c9bdf3c542b44746f6e03006bb68728fa474 100644 (file)
@@ -160,7 +160,7 @@ serbian_to_latin (const char *input, size_t input_len,
   /* Since sequences of 2 bytes are sequences of at most 3 bytes, the size
      of the output will be at most 1.5 * input_len.  */
   size_t allocated = input_len + (input_len >> 1);
-  char *output = (char *) xmalloc (allocated);
+  char *output = XNMALLOC (allocated, char);
 
   const char *input_end = input + input_len;
   const char *ip;
index 3408f3d75e1c7e9415b24054805ae3e726818205..8cdbc5ad431a4d3a5b165b8994ba2f99e95ce4fb 100644 (file)
@@ -430,7 +430,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index 70f9d5eef8d2185366287c8d1836b69f227d32fd..8f1e3cbe1c0bd2215ddfa796e51f1b7b206251a3 100644 (file)
@@ -530,7 +530,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index df34701827e6c8abb680b0e8e3c94e1bd8426f8f..b953f413acb653a6e7e75b24c5a159d61e4bcae8 100644 (file)
@@ -789,14 +789,14 @@ format_parse (const char *format, bool translated, bool objc_extensions,
         of unnumbered arguments.  */
       spec.unnumbered_arg_count = numbered_arg_count;
       spec.allocated = spec.unnumbered_arg_count;
-      spec.unnumbered = (struct unnumbered_arg *) xmalloc (spec.allocated * sizeof (struct unnumbered_arg));
+      spec.unnumbered = XNMALLOC (spec.allocated, struct unnumbered_arg);
       for (i = 0; i < spec.unnumbered_arg_count; i++)
        spec.unnumbered[i].type = numbered[i].type;
       free (numbered);
       numbered_arg_count = 0;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -918,8 +918,7 @@ get_sysdep_c_format_directives (const char *string, bool translated,
   if (descr != NULL && descr->sysdep_directives_count > 0)
     {
       unsigned int n = descr->sysdep_directives_count;
-      struct interval *intervals =
-       (struct interval *) xmalloc (n * sizeof (struct interval));
+      struct interval *intervals = XNMALLOC (n, struct interval);
       unsigned int i;
 
       for (i = 0; i < n; i++)
index 2fd759354689dae02bca48c5f0365e45507fbea7..e72506e3f037d4a89e58e4903ec06fb2ddddd660 100644 (file)
@@ -156,7 +156,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        }
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
index 9e99261b9aee6488b5cd42a193799af45f44dacc..b47a2627787820f153b46b067345b6a95926aaa9 100644 (file)
@@ -278,7 +278,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index d2a006bddb2e9ea93b35ca7f6b576cb9ed8ce182..ee15eff83529ff80afceec4c09db10500fff0b91 100644 (file)
@@ -528,7 +528,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index 936297d102ced0db5f83747cc1da3afbe0d41634..38aaaa399e9d410a99b7f43585ddf69ed5b99243 100644 (file)
@@ -670,7 +670,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index f7613602a753c2fec01ff79ec3e389d3a0ae0254..c44c9683e5dda96add60bd6b5fa8069ef0ff7b41 100644 (file)
@@ -242,7 +242,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index b9b6ad7287472a8be40ac23798581daab5cbaae2..4dd6bbf0de4aa2a95f73ae49590019053f734b31 100644 (file)
@@ -239,8 +239,7 @@ copy_list (const struct format_arg_list *list)
 
   VERIFY_LIST (list);
 
-  newlist =
-    (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  newlist = XMALLOC (struct format_arg_list);
 
   newlist->initial.count = newlist->initial.allocated = list->initial.count;
   length = 0;
@@ -249,8 +248,7 @@ copy_list (const struct format_arg_list *list)
   else
     {
       newlist->initial.element =
-       (struct format_arg *)
-       xmalloc (newlist->initial.allocated * sizeof (struct format_arg));
+       XNMALLOC (newlist->initial.allocated, struct format_arg);
       for (i = 0; i < list->initial.count; i++)
        {
          copy_element (&newlist->initial.element[i],
@@ -268,8 +266,7 @@ copy_list (const struct format_arg_list *list)
   else
     {
       newlist->repeated.element =
-       (struct format_arg *)
-       xmalloc (newlist->repeated.allocated * sizeof (struct format_arg));
+       XNMALLOC (newlist->repeated.allocated, struct format_arg);
       for (i = 0; i < list->repeated.count; i++)
        {
          copy_element (&newlist->repeated.element[i],
@@ -598,15 +595,14 @@ make_unconstrained_list ()
 {
   struct format_arg_list *list;
 
-  list = (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
   list->initial.length = 0;
   list->repeated.count = 1;
   list->repeated.allocated = 1;
-  list->repeated.element =
-    (struct format_arg *) xmalloc (1 * sizeof (struct format_arg));
+  list->repeated.element = XNMALLOC (1, struct format_arg);
   list->repeated.element[0].repcount = 1;
   list->repeated.element[0].presence = FCT_OPTIONAL;
   list->repeated.element[0].type = FAT_OBJECT;
@@ -625,7 +621,7 @@ make_empty_list ()
 {
   struct format_arg_list *list;
 
-  list = (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -760,9 +756,7 @@ rotate_loop (struct format_arg_list *list, unsigned int m)
 
          oldcount = list->repeated.count;
          newcount = list->repeated.count + (t > 0 ? 1 : 0);
-         newelement =
-           (struct format_arg *)
-           xmalloc (newcount * sizeof (struct format_arg));
+         newelement = XNMALLOC (newcount, struct format_arg);
          i = 0;
          for (j = s; j < oldcount; j++, i++)
            newelement[i] = list->repeated.element[j];
@@ -1160,8 +1154,7 @@ make_intersected_list (struct format_arg_list *list1,
     }
 
   /* Step 3: Allocate the result.  */
-  result =
-    (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  result = XMALLOC (struct format_arg_list);
   result->initial.count = 0;
   result->initial.allocated = 0;
   result->initial.element = NULL;
@@ -1538,8 +1531,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
     }
 
   /* Step 3: Allocate the result.  */
-  result =
-    (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  result = XMALLOC (struct format_arg_list);
   result->initial.count = 0;
   result->initial.allocated = 0;
   result->initial.element = NULL;
@@ -1719,8 +1711,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
       result->repeated.count = list1->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
-       (struct format_arg *)
-       xmalloc (result->repeated.allocated * sizeof (struct format_arg));
+       XNMALLOC (result->repeated.allocated, struct format_arg);
       for (i = 0; i < list1->repeated.count; i++)
        copy_element (&result->repeated.element[i],
                      &list1->repeated.element[i]);
@@ -1735,8 +1726,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
       result->repeated.count = list2->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
-       (struct format_arg *)
-       xmalloc (result->repeated.allocated * sizeof (struct format_arg));
+       XNMALLOC (result->repeated.allocated, struct format_arg);
       for (i = 0; i < list2->repeated.count; i++)
        copy_element (&result->repeated.element[i],
                      &list2->repeated.element[i]);
@@ -2058,8 +2048,7 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
     {
       struct format_arg_list *listlist;
 
-      listlist =
-       (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+      listlist = XMALLOC (struct format_arg_list);
 
       listlist->initial.count = 0;
       listlist->initial.allocated = 0;
@@ -2067,8 +2056,7 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
       listlist->initial.length = 0;
       listlist->repeated.count = 1;
       listlist->repeated.allocated = 1;
-      listlist->repeated.element =
-       (struct format_arg *) xmalloc (1 * sizeof (struct format_arg));
+      listlist->repeated.element = XNMALLOC (1, struct format_arg);
       listlist->repeated.element[0].repcount = 1;
       listlist->repeated.element[0].presence = FCT_OPTIONAL;
       listlist->repeated.element[0].type = FAT_LIST;
@@ -2131,9 +2119,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period)
         segment.  */
       tmp.count = sublist->initial.count + sublist->repeated.count;
       tmp.allocated = tmp.count;
-      tmp.element =
-       (struct format_arg *)
-       xmalloc (tmp.allocated * sizeof (struct format_arg));
+      tmp.element = XNMALLOC (tmp.allocated, struct format_arg);
       for (i = 0; i < sublist->initial.count; i++)
        tmp.element[i] = sublist->initial.element[i];
       for (j = 0; j < sublist->repeated.count; i++, j++)
@@ -2158,7 +2144,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period)
      Or by a single incremental intersection operation, going from left
      to right.  */
 
-  list = (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -2275,8 +2261,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period)
       if (newcount > list->repeated.allocated)
        {
          list->repeated.allocated = newcount;
-         list->repeated.element =
-           (struct format_arg *) xmalloc (newcount * sizeof (struct format_arg));
+         list->repeated.element = XNMALLOC (newcount, struct format_arg);
        }
       for (i = splitindex, j = 0; i < n; i++, j++)
        list->repeated.element[j] = list->initial.element[i];
@@ -3305,7 +3290,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
   /* Normalize the result.  */
   normalize_list (spec.list);
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
index 1d0996aefbf0db25bfbabbe110168fd21487fe9f..0857aa4796f8861507f8a305975e66166c1429e8 100644 (file)
@@ -328,7 +328,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   result->directives = directives;
   result->numbered_arg_count = numbered_arg_count;
   result->allocated = allocated;
index 1d3877b9bc6a97931d8280bcf70b2449b959a125..dfc45ae197a3a2609e89804d2e50ed42bbff9819 100644 (file)
@@ -91,7 +91,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
                const char *name_end = f;
                size_t n = name_end - name_start;
 
-               name = (char *) xmalloc (n + 1);
+               name = XNMALLOC (n + 1, char);
                memcpy (name, name_start, n);
                name[n] = '\0';
 
@@ -131,7 +131,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
       spec.named_arg_count = j;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
index f20c49d9e7e5ef176435999ba7bcf13c52885d41..1c928099b02681d5a567d0f68a242fa2637b9ff5 100644 (file)
@@ -510,7 +510,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   result->directives = directives;
   result->numbered_arg_count = numbered_arg_count;
   result->allocated = allocated;
index 7ed24c25b4ce5e7bfa7691d9f76d5e2bbe412428..601a033d551e6cd5ad69312a3a4315b57bcf7f43 100644 (file)
@@ -275,7 +275,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   result->directives = directives;
   result->numbered_arg_count = numbered_arg_count;
   result->allocated = allocated;
index 35012e35a34ae9976010fa2bbcbc5b4adf66086d..e8a973a5f626f8a070d2923f509a03c960b0b853 100644 (file)
@@ -163,7 +163,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
            name_end = format++;
 
            n = name_end - name_start;
-           name = (char *) xmalloc (n + 1);
+           name = XNMALLOC (n + 1, char);
            memcpy (name, name_start, n);
            name[n] = '\0';
          }
@@ -346,7 +346,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index aa51a93c5ab150c0f07f4db91c6eed289ed545c5..67aad7a594a438f6fbab05fb59c818a1ef3a9028 100644 (file)
@@ -83,7 +83,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
          format++;
        }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index b4300c40166a734a7dae17bda4314baba4e1041c..78ee865b93183949b498b56091f61c1739960064 100644 (file)
@@ -242,8 +242,7 @@ copy_list (const struct format_arg_list *list)
 
   VERIFY_LIST (list);
 
-  newlist =
-    (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  newlist = XMALLOC (struct format_arg_list);
 
   newlist->initial.count = newlist->initial.allocated = list->initial.count;
   length = 0;
@@ -252,8 +251,7 @@ copy_list (const struct format_arg_list *list)
   else
     {
       newlist->initial.element =
-       (struct format_arg *)
-       xmalloc (newlist->initial.allocated * sizeof (struct format_arg));
+       XNMALLOC (newlist->initial.allocated, struct format_arg);
       for (i = 0; i < list->initial.count; i++)
        {
          copy_element (&newlist->initial.element[i],
@@ -271,8 +269,7 @@ copy_list (const struct format_arg_list *list)
   else
     {
       newlist->repeated.element =
-       (struct format_arg *)
-       xmalloc (newlist->repeated.allocated * sizeof (struct format_arg));
+       XNMALLOC (newlist->repeated.allocated, struct format_arg);
       for (i = 0; i < list->repeated.count; i++)
        {
          copy_element (&newlist->repeated.element[i],
@@ -601,15 +598,14 @@ make_unconstrained_list ()
 {
   struct format_arg_list *list;
 
-  list = (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
   list->initial.length = 0;
   list->repeated.count = 1;
   list->repeated.allocated = 1;
-  list->repeated.element =
-    (struct format_arg *) xmalloc (1 * sizeof (struct format_arg));
+  list->repeated.element = XNMALLOC (1, struct format_arg);
   list->repeated.element[0].repcount = 1;
   list->repeated.element[0].presence = FCT_OPTIONAL;
   list->repeated.element[0].type = FAT_OBJECT;
@@ -628,7 +624,7 @@ make_empty_list ()
 {
   struct format_arg_list *list;
 
-  list = (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -763,9 +759,7 @@ rotate_loop (struct format_arg_list *list, unsigned int m)
 
          oldcount = list->repeated.count;
          newcount = list->repeated.count + (t > 0 ? 1 : 0);
-         newelement =
-           (struct format_arg *)
-           xmalloc (newcount * sizeof (struct format_arg));
+         newelement = XNMALLOC (newcount, struct format_arg);
          i = 0;
          for (j = s; j < oldcount; j++, i++)
            newelement[i] = list->repeated.element[j];
@@ -1173,8 +1167,7 @@ make_intersected_list (struct format_arg_list *list1,
     }
 
   /* Step 3: Allocate the result.  */
-  result =
-    (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  result = XMALLOC (struct format_arg_list);
   result->initial.count = 0;
   result->initial.allocated = 0;
   result->initial.element = NULL;
@@ -1561,8 +1554,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
     }
 
   /* Step 3: Allocate the result.  */
-  result =
-    (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  result = XMALLOC (struct format_arg_list);
   result->initial.count = 0;
   result->initial.allocated = 0;
   result->initial.element = NULL;
@@ -1742,8 +1734,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
       result->repeated.count = list1->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
-       (struct format_arg *)
-       xmalloc (result->repeated.allocated * sizeof (struct format_arg));
+       XNMALLOC (result->repeated.allocated, struct format_arg);
       for (i = 0; i < list1->repeated.count; i++)
        copy_element (&result->repeated.element[i],
                      &list1->repeated.element[i]);
@@ -1758,8 +1749,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
       result->repeated.count = list2->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
-       (struct format_arg *)
-       xmalloc (result->repeated.allocated * sizeof (struct format_arg));
+       XNMALLOC (result->repeated.allocated, struct format_arg);
       for (i = 0; i < list2->repeated.count; i++)
        copy_element (&result->repeated.element[i],
                      &list2->repeated.element[i]);
@@ -2081,8 +2071,7 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
     {
       struct format_arg_list *listlist;
 
-      listlist =
-       (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+      listlist = XMALLOC (struct format_arg_list);
 
       listlist->initial.count = 0;
       listlist->initial.allocated = 0;
@@ -2090,8 +2079,7 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
       listlist->initial.length = 0;
       listlist->repeated.count = 1;
       listlist->repeated.allocated = 1;
-      listlist->repeated.element =
-       (struct format_arg *) xmalloc (1 * sizeof (struct format_arg));
+      listlist->repeated.element = XNMALLOC (1, struct format_arg);
       listlist->repeated.element[0].repcount = 1;
       listlist->repeated.element[0].presence = FCT_OPTIONAL;
       listlist->repeated.element[0].type = FAT_LIST;
@@ -2154,9 +2142,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period)
         segment.  */
       tmp.count = sublist->initial.count + sublist->repeated.count;
       tmp.allocated = tmp.count;
-      tmp.element =
-       (struct format_arg *)
-       xmalloc (tmp.allocated * sizeof (struct format_arg));
+      tmp.element = XNMALLOC (tmp.allocated, struct format_arg);
       for (i = 0; i < sublist->initial.count; i++)
        tmp.element[i] = sublist->initial.element[i];
       for (j = 0; j < sublist->repeated.count; i++, j++)
@@ -2181,7 +2167,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period)
      Or by a single incremental intersection operation, going from left
      to right.  */
 
-  list = (struct format_arg_list *) xmalloc (sizeof (struct format_arg_list));
+  list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -2298,8 +2284,7 @@ make_repeated_list (struct format_arg_list *sublist, unsigned int period)
       if (newcount > list->repeated.allocated)
        {
          list->repeated.allocated = newcount;
-         list->repeated.element =
-           (struct format_arg *) xmalloc (newcount * sizeof (struct format_arg));
+         list->repeated.element = XNMALLOC (newcount, struct format_arg);
        }
       for (i = splitindex, j = 0; i < n; i++, j++)
        list->repeated.element[j] = list->initial.element[i];
@@ -3243,7 +3228,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
   /* Normalize the result.  */
   normalize_list (spec.list);
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
index 176177fc574699252b0b0ae5936209a834e115e7..8390e7226c6a484197b9b21b4bd72ff89731722e 100644 (file)
@@ -147,7 +147,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
                *invalid_reason = INVALID_EMPTY_VARIABLE ();
                goto bad_format;
              }
-           name = (char *) xmalloc (n + 1);
+           name = XNMALLOC (n + 1, char);
            memcpy (name, name_start, n);
            name[n] = '\0';
          }
@@ -164,7 +164,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
            name_end = format;
 
            n = name_end - name_start;
-           name = (char *) xmalloc (n + 1);
+           name = XNMALLOC (n + 1, char);
            memcpy (name, name_start, n);
            name[n] = '\0';
          }
@@ -218,7 +218,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
       spec.named_arg_count = j;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index a8e006c2fabd169bcbbdf84e57485038db74d969..f98add8a912bf428cca54015a875149e84adf6e9 100644 (file)
@@ -317,7 +317,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
        goto bad_format;
     }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index 8acbf6b531c24f3cf67cef731112fbd78acad68c..8929cffaac2fafe42acaf668594adc69f37b0ebb 100644 (file)
@@ -86,7 +86,7 @@ format_parse (const char *format, bool translated, char **invalid_reason)
          }
       }
 
-  result = (struct spec *) xmalloc (sizeof (struct spec));
+  result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
index 1bf04511047041b438623bfeb1fad47af36d2a08..b7019f3056202e5828bcdbd7d1f73cffea87dc29 100644 (file)
@@ -102,7 +102,7 @@ message_alloc (const char *msgctxt,
   message_ty *mp;
   size_t i;
 
-  mp = (message_ty *) xmalloc (sizeof (message_ty));
+  mp = XMALLOC (message_ty);
   mp->msgctxt = msgctxt;
   mp->msgid = msgid;
   mp->msgid_plural = (msgid_plural != NULL ? xstrdup (msgid_plural) : NULL);
@@ -241,7 +241,7 @@ message_list_alloc (bool use_hashtable)
 {
   message_list_ty *mlp;
 
-  mlp = (message_list_ty *) xmalloc (sizeof (message_list_ty));
+  mlp = XMALLOC (message_list_ty);
   mlp->nitems = 0;
   mlp->nitems_max = 0;
   mlp->item = NULL;
@@ -576,7 +576,7 @@ message_list_list_alloc ()
 {
   message_list_list_ty *mllp;
 
-  mllp = (message_list_list_ty *) xmalloc (sizeof (message_list_list_ty));
+  mllp = XMALLOC (message_list_list_ty);
   mllp->nitems = 0;
   mllp->nitems_max = 0;
   mllp->item = NULL;
@@ -686,7 +686,7 @@ msgdomain_alloc (const char *domain, bool use_hashtable)
 {
   msgdomain_ty *mdp;
 
-  mdp = (msgdomain_ty *) xmalloc (sizeof (msgdomain_ty));
+  mdp = XMALLOC (msgdomain_ty);
   mdp->domain = domain;
   mdp->messages = message_list_alloc (use_hashtable);
   return mdp;
@@ -706,13 +706,12 @@ msgdomain_list_alloc (bool use_hashtable)
 {
   msgdomain_list_ty *mdlp;
 
-  mdlp = (msgdomain_list_ty *) xmalloc (sizeof (msgdomain_list_ty));
+  mdlp = XMALLOC (msgdomain_list_ty);
   /* Put the default domain first, so that when we output it,
      we can omit the 'domain' directive.  */
   mdlp->nitems = 1;
   mdlp->nitems_max = 1;
-  mdlp->item =
-    (msgdomain_ty **) xmalloc (mdlp->nitems_max * sizeof (msgdomain_ty *));
+  mdlp->item = XNMALLOC (mdlp->nitems_max, msgdomain_ty *);
   mdlp->item[0] = msgdomain_alloc (MESSAGE_DOMAIN_DEFAULT, use_hashtable);
   mdlp->use_hashtable = use_hashtable;
   mdlp->encoding = NULL;
index 3af467acd31f3be7d8ebfb878ae24d1b495f4d5b..65b02db13c43fef5f6af839c163a452f7346507b 100644 (file)
@@ -197,7 +197,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
 
   /* Build argument list for the program.  */
   sub_argc = argc - optind;
-  sub_argv = (char **) xmalloc ((sub_argc + 1) * sizeof (char *));
+  sub_argv = XNMALLOC (sub_argc + 1, char *);
   for (i = 0; i < sub_argc; i++)
     sub_argv[i] = argv[optind + i];
   sub_argv[i] = NULL;
index 8a15c7fcd4dc695a18a9144dab170e248007782e..d0b63394b8f6bbc605441531251a37e1459b5a85 100644 (file)
@@ -312,7 +312,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
 
   /* Build argument list for the program.  */
   sub_argc = argc - optind;
-  sub_argv = (char **) xmalloc ((sub_argc + 1) * sizeof (char *));
+  sub_argv = XNMALLOC (sub_argc + 1, char *);
   for (i = 0; i < sub_argc; i++)
     sub_argv[i] = argv[optind + i];
   sub_argv[i] = NULL;
@@ -618,7 +618,7 @@ generic_filter (const char *str, size_t len, char **resultp, size_t *lengthp)
   }
 
   allocated = len + (len >> 2) + 1;
-  result = (char *) xmalloc (allocated);
+  result = XNMALLOC (allocated, char);
   length = 0;
 
   for (;;)
@@ -776,7 +776,7 @@ process_message (message_ty *mp)
        p += strlen (p) + 1, nsubstrings++);
 
   /* Process each NUL delimited substring separately.  */
-  substrings = (char **) xmalloc (nsubstrings * sizeof (char *));
+  substrings = XNMALLOC (nsubstrings, char *);
   for (p = msgstr, k = 0, total_len = 0; k < nsubstrings; k++)
     {
       char *result;
@@ -792,7 +792,7 @@ process_message (message_ty *mp)
     }
 
   /* Concatenate the results, including the NUL after each.  */
-  total_str = (char *) xmalloc (total_len);
+  total_str = XNMALLOC (total_len, char);
   for (k = 0, q = total_str; k < nsubstrings; k++)
     {
       size_t length = strlen (substrings[k]);
index 642bbe4d521e7a4665540d970c608533ea1fc530..c1a2deabf8bbdeeabdc29ab0b9fb59848ea82d5b 100644 (file)
@@ -775,7 +775,7 @@ add_mo_suffix (const char *fname)
     return fname;
   if (len > 4 && memcmp (fname + len - 4, ".gmo", 4) == 0)
     return fname;
-  result = (char *) xmalloc (len + 4);
+  result = XNMALLOC (len + 4, char);
   stpcpy (stpcpy (result, fname), ".mo");
   return result;
 }
@@ -793,7 +793,7 @@ new_domain (const char *name, const char *file_name)
     {
       struct msg_domain *domain;
 
-      domain = (struct msg_domain *) xmalloc (sizeof (struct msg_domain));
+      domain = XMALLOC (struct msg_domain);
       domain->mlp = message_list_alloc (true);
       domain->domain_name = name;
       domain->file_name = file_name;
index c44439b9357d4c1bb86fc89591f42a9c4be0fa44..a561672f4f0647fc2eaffe76054738409f09d7dd 100644 (file)
@@ -688,7 +688,7 @@ catalogname_for_locale (const char *locale)
       if (codeset_end == NULL)
        codeset_end = dot + strlen (dot);
 
-      shorter_locale = (char *) xmalloc (strlen (locale));
+      shorter_locale = XNMALLOC (strlen (locale), char);
       memcpy (shorter_locale, locale, dot - locale);
       strcpy (shorter_locale + (dot - locale), codeset_end);
       locale = shorter_locale;
@@ -707,7 +707,7 @@ catalogname_for_locale (const char *locale)
          abort ();
 
        len = language_end - locale;
-       shorter_locale = (char *) xmalloc (len + 1);
+       shorter_locale = XNMALLOC (len + 1, char);
        memcpy (shorter_locale, locale, len);
        shorter_locale[len] = '\0';
        locale = shorter_locale;
@@ -731,7 +731,7 @@ language_of_locale (const char *locale)
       char *result;
 
       len = language_end - locale;
-      result = (char *) xmalloc (len + 1);
+      result = XNMALLOC (len + 1, char);
       memcpy (result, locale, len);
       result[len] = '\0';
 
@@ -1019,7 +1019,7 @@ get_user_fullname ()
       if (fullname_end == NULL)
        fullname_end = fullname + strlen (fullname);
 
-      result = (char *) xmalloc (fullname_end - fullname + 1);
+      result = XNMALLOC (fullname_end - fullname + 1, char);
       memcpy (result, fullname, fullname_end - fullname);
       result[fullname_end - fullname] = '\0';
 
@@ -1300,7 +1300,7 @@ get_field (const char *header, const char *field)
          if (value_end == NULL)
            value_end = value_start + strlen (value_start);
 
-         value = (char *) xmalloc (value_end - value_start + 1);
+         value = XNMALLOC (value_end - value_start + 1, char);
          memcpy (value, value_start, value_end - value_start);
          value[value_end - value_start] = '\0';
 
@@ -1339,11 +1339,12 @@ put_field (const char *old_header, const char *field, const char *value)
          if (value_end == NULL)
            value_end = value_start + strlen (value_start);
 
-         new_header = (char *) xmalloc (strlen (old_header)
-                                        - (value_end - value_start)
-                                        + strlen (value)
-                                        + (*value_end != '\n' ? 1 : 0)
-                                        + 1);
+         new_header = XNMALLOC (strlen (old_header)
+                                - (value_end - value_start)
+                                + strlen (value)
+                                + (*value_end != '\n' ? 1 : 0)
+                                + 1,
+                                char);
          p = new_header;
          memcpy (p, old_header, value_start - old_header);
          p += value_start - old_header;
@@ -1363,9 +1364,10 @@ put_field (const char *old_header, const char *field, const char *value)
        break;
     }
 
-  new_header = (char *) xmalloc (strlen (old_header) + 1
-                                + len + 2 + strlen (value) + 1
-                                + 1);
+  new_header = XNMALLOC (strlen (old_header) + 1
+                        + len + 2 + strlen (value) + 1
+                        + 1,
+                        char);
   p = new_header;
   memcpy (p, old_header, strlen (old_header));
   p += strlen (old_header);
@@ -1502,7 +1504,7 @@ subst_string (const char *str,
              {
                size_t replacement_len = strlen (subst[j][1]);
                size_t new_len = strlen (str) - substlen[j] + replacement_len;
-               char *new_str = (char *) xmalloc (new_len + 1);
+               char *new_str = XNMALLOC (new_len + 1, char);
                memcpy (new_str, str, i);
                memcpy (new_str + i, subst[j][1], replacement_len);
                strcpy (new_str + i + replacement_len, str + i + substlen[j]);
@@ -1644,7 +1646,7 @@ update_msgstr_plurals (msgdomain_list_ty *mdlp)
 
       header_entry = message_list_search (mlp, NULL, "");
       nplurals = get_plural_count (header_entry ? header_entry->msgstr : NULL);
-      untranslated_plural_msgstr = (char *) xmalloc (nplurals);
+      untranslated_plural_msgstr = XNMALLOC (nplurals, char);
       memset (untranslated_plural_msgstr, '\0', nplurals);
 
       for (j = 0; j < mlp->nitems; j++)
index 02ffe730aa45296514b9bb16dfdb84bf4a2527b1..38e042378f8345c6c954189b1b055f5673a12749 100644 (file)
@@ -118,20 +118,18 @@ catenate_msgdomain_list (string_list_ty *file_list,
   size_t n, j;
 
   /* Read input files.  */
-  mdlps =
-    (msgdomain_list_ty **) xmalloc (nfiles * sizeof (msgdomain_list_ty *));
+  mdlps = XNMALLOC (nfiles, msgdomain_list_ty *);
   for (n = 0; n < nfiles; n++)
     mdlps[n] = read_catalog_file (files[n], input_syntax);
 
   /* Determine the canonical name of each input file's encoding.  */
-  canon_charsets = (const char ***) xmalloc (nfiles * sizeof (const char **));
+  canon_charsets = XNMALLOC (nfiles, const char **);
   for (n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
       size_t k;
 
-      canon_charsets[n] =
-       (const char **) xmalloc (mdlp->nitems * sizeof (const char *));
+      canon_charsets[n] = XNMALLOC (mdlp->nitems, const char *);
       for (k = 0; k < mdlp->nitems; k++)
        {
          message_list_ty *mlp = mdlp->item[k]->messages;
@@ -217,15 +215,14 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s
     }
 
   /* Determine textual identifications of each file/domain combination.  */
-  identifications = (const char ***) xmalloc (nfiles * sizeof (const char **));
+  identifications = XNMALLOC (nfiles, const char **);
   for (n = 0; n < nfiles; n++)
     {
       const char *filename = basename (files[n]);
       msgdomain_list_ty *mdlp = mdlps[n];
       size_t k;
 
-      identifications[n] =
-       (const char **) xmalloc (mdlp->nitems * sizeof (const char *));
+      identifications[n] = XNMALLOC (mdlp->nitems, const char *);
       for (k = 0; k < mdlp->nitems; k++)
        {
          const char *domain = mdlp->item[k]->domain;
@@ -257,7 +254,7 @@ domain \"%s\" in input file `%s' doesn't contain a header entry with a charset s
                        if (cp < endp)
                          {
                            size_t len = endp - cp;
-                           project_id = (char *) xmalloc (len + 1);
+                           project_id = XNMALLOC (len + 1, char);
                            memcpy (project_id, cp, len);
                            project_id[len] = '\0';
                          }
@@ -664,7 +661,7 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
                          len += id_len + 2;
                      }
 
-                   new_msgstr = (char *) xmalloc (len);
+                   new_msgstr = XNMALLOC (len, char);
                    np = new_msgstr;
                    for (;;)
                      {
index 4d7a5c1eb72684e18063c4437d508e84e8e4ba92..67ef53c31567f9abd7d68aa32b27b6644c3c726b 100644 (file)
@@ -67,7 +67,7 @@ check_plural_eval (struct expression *plural_expr,
 
   /* Allocate a distribution array.  */
   if (nplurals_value <= 100)
-    distribution = (unsigned char *) xcalloc (nplurals_value, 1);
+    distribution = XCALLOC (nplurals_value, unsigned char);
   else
     /* nplurals_value is nonsense.  Don't risk an out-of-memory.  */
     distribution = NULL;
index 87c6c2ae8cd0b8499dfaa18b05aab3ef2bae33a8..1106bb7e8195f0240bba00432a9ae14bccd94d04 100644 (file)
@@ -1,5 +1,5 @@
 /* Message translation initialization for English.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2006 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
@@ -57,7 +57,7 @@ msgdomain_list_english (msgdomain_list_ty *mdlp)
                {
                  size_t len0 = strlen (mp->msgid) + 1;
                  size_t len1 = strlen (mp->msgid_plural) + 1;
-                 char *cp = (char *) xmalloc (len0 + len1);
+                 char *cp = XNMALLOC (len0 + len1, char);
                  memcpy (cp, mp->msgid, len0);
                  memcpy (cp + len0, mp->msgid_plural, len1);
                  mp->msgstr = cp;
index fa69f99540b5b1abe6a3985a6b8a555d1ca5cf04..a323de56decd04c9e3ff3db4e5a48a6620f644fd 100644 (file)
@@ -92,7 +92,7 @@ typedef index_ty *index_list_ty;
 static inline index_list_ty
 new_index (index_ty idx)
 {
-  index_ty *list = (index_ty *) xmalloc ((2 + 1) * sizeof (index_ty));
+  index_ty *list = XNMALLOC (2 + 1, index_ty);
   list[IL_ALLOCATED] = 1;
   list[IL_LENGTH] = 1;
   list[2] = idx;
@@ -203,8 +203,7 @@ message_fuzzy_index_ty *
 message_fuzzy_index_alloc (const message_list_ty *mlp,
                           const char *canon_charset)
 {
-  message_fuzzy_index_ty *findex =
-    (message_fuzzy_index_ty *) xmalloc (sizeof (message_fuzzy_index_ty));
+  message_fuzzy_index_ty *findex = XMALLOC (message_fuzzy_index_ty);
   size_t count = mlp->nitems;
   size_t j;
   size_t l;
@@ -386,8 +385,7 @@ mult_index_list_accumulate (struct mult_index_list *accu, index_list_ty list)
        new_max = need;
       if (accu->item2 != NULL)
        free (accu->item2);
-      accu->item2 =
-       (struct mult_index *) xmalloc (new_max * sizeof (struct mult_index));
+      accu->item2 = XNMALLOC (new_max, struct mult_index);
       accu->nitems2_max = new_max;
     }
 
index 0a451c26034ff97190865da4eff2245071103f8e..24826334c523203f006f3b86201389ae0ba8bde0 100644 (file)
@@ -244,7 +244,7 @@ two different charsets \"%s\" and \"%s\" in input file"),
                len1 = charsetstr - header;
                len2 = strlen (canon_to_code);
                len3 = (header + strlen (header)) - (charsetstr + len);
-               new_header = (char *) xmalloc (len1 + len2 + len3 + 1);
+               new_header = XNMALLOC (len1 + len2 + len3 + 1, char);
                memcpy (new_header, header, len1);
                memcpy (new_header + len1, canon_to_code, len2);
                memcpy (new_header + len1 + len2, charsetstr + len, len3 + 1);
index cda1a2f55fdaad2bbba606257edd482840f60261..be0b920d03504b511de889e0c8e97ff22e8c7d0f 100644 (file)
@@ -963,7 +963,7 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy)
          len += known_fields[cnt].len + header_fields[cnt].len;
       len += header_fields[UNKNOWN].len;
 
-      cp = newp = (char *) xmalloc (len + 1);
+      cp = newp = XNMALLOC (len + 1, char);
       newp[len] = '\0';
 
 #define IF_FILLED(idx)                                                       \
@@ -1116,15 +1116,13 @@ match_domain (const char *fn1, const char *fn2,
   header_entry =
     message_list_search (definitions_current_list (definitions), NULL, "");
   nplurals = get_plural_count (header_entry ? header_entry->msgstr : NULL);
-  untranslated_plural_msgstr = (char *) xmalloc (nplurals);
+  untranslated_plural_msgstr = XNMALLOC (nplurals, char);
   memset (untranslated_plural_msgstr, '\0', nplurals);
 
   /* Most of the time is spent in definitions_search_fuzzy.
      Perform it in a separate loop that can be parallelized by an OpenMP
      capable compiler.  */
-  search_results =
-    (struct search_result *)
-    xmalloc (refmlp->nitems * sizeof (struct search_result));
+  search_results = XNMALLOC (refmlp->nitems, struct search_result);
   {
     long int nn = refmlp->nitems;
     long int jj;
@@ -1320,7 +1318,7 @@ this message should define plural forms"));
                  }
 
                new_msgstr_len = nplurals * mp->msgstr_len;
-               new_msgstr = (char *) xmalloc (new_msgstr_len);
+               new_msgstr = XNMALLOC (new_msgstr_len, char);
                for (i = 0, p = new_msgstr; i < nplurals; i++)
                  {
                    memcpy (p, mp->msgstr, mp->msgstr_len);
index 61f73f61fb6535ee8f8dcd7c4f5f8654cf5ea450..6735cd6e5cabc5e47aff7f3f6e63778075c89dc3 100644 (file)
@@ -373,7 +373,7 @@ pluralform_list
        | pluralform_list pluralform
                {
                  check_obsolete ($1, $2);
-                 $$.rhs.msgstr = (char *) xmalloc ($1.rhs.msgstr_len + $2.rhs.msgstr_len);
+                 $$.rhs.msgstr = XNMALLOC ($1.rhs.msgstr_len + $2.rhs.msgstr_len, char);
                  memcpy ($$.rhs.msgstr, $1.rhs.msgstr, $1.rhs.msgstr_len);
                  memcpy ($$.rhs.msgstr + $1.rhs.msgstr_len, $2.rhs.msgstr, $2.rhs.msgstr_len);
                  $$.rhs.msgstr_len = $1.rhs.msgstr_len + $2.rhs.msgstr_len;
index 0d88a2b1a4ffaf26c7849eff005f6a11f70b10d4..653d362f72df383030c06b4a76de391fd2f9ea74 100644 (file)
@@ -407,7 +407,7 @@ po_parse_comment_filepos (const char *s)
                        /* Parsed a GNU style file comment with spaces.  */
                        const char *string_end = s;
                        size_t string_length = string_end - string_start;
-                       char *string = (char *) xmalloc (string_length + 1);
+                       char *string = XNMALLOC (string_length + 1, char);
 
                        memcpy (string, string_start, string_length);
                        string[string_length] = '\0';
@@ -449,7 +449,7 @@ po_parse_comment_filepos (const char *s)
                      /* Parsed a GNU style file comment with spaces.  */
                      const char *string_end = s - 1;
                      size_t string_length = string_end - string_start;
-                     char *string = (char *) xmalloc (string_length + 1);
+                     char *string = XNMALLOC (string_length + 1, char);
 
                      memcpy (string, string_start, string_length);
                      string[string_length] = '\0';
@@ -502,7 +502,7 @@ po_parse_comment_filepos (const char *s)
 
                  {
                    size_t string_length = string_end - string_start;
-                   char *string = (char *) xmalloc (string_length + 1);
+                   char *string = XNMALLOC (string_length + 1, char);
 
                    memcpy (string, string_start, string_length);
                    string[string_length] = '\0';
@@ -521,7 +521,7 @@ po_parse_comment_filepos (const char *s)
          {
            const char *string_end = s;
            size_t string_length = string_end - string_start;
-           char *string = (char *) xmalloc (string_length + 1);
+           char *string = XNMALLOC (string_length + 1, char);
 
            memcpy (string, string_start, string_length);
            string[string_length] = '\0';
@@ -620,7 +620,7 @@ po_parse_comment_solaris_filepos (const char *s)
                              /* Parsed a Sun style file comment.  */
                              size_t string_length = string_end - string_start;
                              char *string =
-                               (char *) xmalloc (string_length + 1);
+                               XNMALLOC (string_length + 1, char);
 
                              memcpy (string, string_start, string_length);
                              string[string_length] = '\0';
index c6bc9d0e9d3feb14698ec13cd2c151cb51e3125f..6f2b392f8588f3d7e3fde9a9dcbc5390bfb4ad93 100644 (file)
@@ -185,7 +185,7 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset,
     }
 
   /* Allocate and fill the string.  */
-  string = (char *) xmalloc (length);
+  string = XNMALLOC (length, char);
   p = string;
   s_offset = get_uint32 (bfp, offset);
   for (i = 4; ; i += 8)
index 19fa539c4ec704cffdcd03c003070c17c35556f4..ac02014c15cddef54772748eca99c3f7d5b81448 100644 (file)
@@ -250,7 +250,7 @@ conv_from_iso_8859_1 (char *string)
     {
       size_t length = strlen (string);
       /* Each ISO-8859-1 character needs 2 bytes at worst.  */
-      unsigned char *utf8_string = (unsigned char *) xmalloc (2 * length + 1);
+      unsigned char *utf8_string = XNMALLOC (2 * length + 1, unsigned char);
       unsigned char *q = utf8_string;
       const char *str = string;
       const char *str_limit = str + length;
@@ -430,7 +430,7 @@ read_escaped_string (bool in_key)
     unsigned char *q;
 
     /* Each UTF-16 word needs 3 bytes at worst.  */
-    utf8_string = (unsigned char *) xmalloc (3 * buflen + 1);
+    utf8_string = XNMALLOC (3 * buflen + 1, unsigned char);
     for (pos = 0, q = utf8_string; pos < buflen; )
       {
        unsigned int uc;
index c1cb64647c08e994422cb7c5887472cc9c6d3d4b..a2dd54c2041a3a58423d8ed0de10756a9f7fe120 100644 (file)
@@ -336,7 +336,7 @@ conv_from_ucs4 (const int *buffer, size_t buflen)
   unsigned char *q;
 
   /* Each UCS-4 word needs 6 bytes at worst.  */
-  utf8_string = (unsigned char *) xmalloc (6 * buflen + 1);
+  utf8_string = XNMALLOC (6 * buflen + 1, unsigned char);
 
   for (pos = 0, q = utf8_string; pos < buflen; )
     {
index 484d9e6bf3cbdf4d9064bebe170c1dec415e6aee..35af5f1f268b17276088041f43293eaa67782324 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995, 1998, 2000-2004 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1998, 2000-2004, 2006 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -47,7 +47,7 @@ string_list_alloc ()
 {
   string_list_ty *slp;
 
-  slp = (string_list_ty *) xmalloc (sizeof (*slp));
+  slp = XMALLOC (string_list_ty);
   slp->item = NULL;
   slp->nitems = 0;
   slp->nitems_max = 0;
@@ -141,7 +141,7 @@ string_list_concat (const string_list_ty *slp)
   len = 1;
   for (j = 0; j < slp->nitems; ++j)
     len += strlen (slp->item[j]);
-  result = (char *) xmalloc (len);
+  result = XNMALLOC (len, char);
   pos = 0;
   for (j = 0; j < slp->nitems; ++j)
     {
@@ -199,7 +199,7 @@ string_list_join (const string_list_ty *slp, char separator,
     }
   if (terminator)
     ++len;
-  result = (char *) xmalloc (len);
+  result = XNMALLOC (len, char);
   pos = 0;
   for (j = 0; j < slp->nitems; ++j)
     {
index 75f9fee83409ad6d2edb437aff5f5fcf1a16baa3..45e00c5bbcd0102995a49520796665d9a1c65328 100644 (file)
@@ -133,7 +133,7 @@ construct_class_name (const char *resource_name)
       static const char hexdigit[] = "0123456789abcdef";
       const char *str = resource_name;
       const char *str_limit = str + strlen (str);
-      char *class_name = (char *) xmalloc (12 + 6 * (str_limit - str) + 1);
+      char *class_name = XNMALLOC (12 + 6 * (str_limit - str) + 1, char);
       char *b;
 
       b = class_name;
@@ -700,7 +700,7 @@ but the C# .dll format doesn't support contexts\n")));
     char *p;
 
     class_name =
-      (char *) xmalloc (strlen (class_name_part1) + 1 + strlen (culture_name) + 1);
+      XNMALLOC (strlen (class_name_part1) + 1 + strlen (culture_name) + 1, char);
     sprintf (class_name, "%s_%s", class_name_part1, culture_name);
     for (p = class_name + strlen (class_name_part1) + 1; *p != '\0'; p++)
       if (*p == '-')
index 6b216460e0a9331e6a68413a15ad0ab2945d6ec1..2f3af2549debf29c6cc40a50b95919d3752e09ad 100644 (file)
@@ -180,7 +180,7 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp)
       if (hashsize >= best_score)
        break;
 
-      bitmap = (char *) xmalloc (hashsize);
+      bitmap = XNMALLOC (hashsize, char);
       memset (bitmap, 0, hashsize);
 
       score = 0;
@@ -293,12 +293,11 @@ static struct table_item *
 compute_table_items (message_list_ty *mlp, unsigned int hashsize)
 {
   unsigned int n = mlp->nitems;
-  struct table_item *arr =
-    (struct table_item *) xmalloc (n * sizeof (struct table_item));
+  struct table_item *arr = XNMALLOC (n, struct table_item);
   char *bitmap;
   size_t j;
 
-  bitmap = (char *) xmalloc (hashsize);
+  bitmap = XNMALLOC (hashsize, char);
   memset (bitmap, 0, hashsize);
 
   for (j = 0; j < n; j++)
index 2ef6810845994d5b34c88797e5c236bf0120e067..f5966bbec96a7d3087b4ca033383462c6fb73d61 100644 (file)
@@ -43,6 +43,7 @@
 #include "hash.h"
 #include "message.h"
 #include "format.h"
+#include "xsize.h"
 #include "xalloc.h"
 #include "xallocsa.h"
 #include "binary-io.h"
@@ -170,15 +171,11 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* First pass: Move the static string pairs into an array, for sorting,
      and at the same time, compute the segments of the system dependent
      strings.  */
-  msgctid_arr = (char **) xmalloc (mlp->nitems * sizeof (char *));
+  msgctid_arr = XNMALLOC (mlp->nitems, char *);
   nstrings = 0;
-  msg_arr =
-    (struct pre_message *)
-    xmalloc (mlp->nitems * sizeof (struct pre_message));
+  msg_arr = XNMALLOC (mlp->nitems, struct pre_message);
   n_sysdep_strings = 0;
-  sysdep_msg_arr =
-    (struct pre_sysdep_message *)
-    xmalloc (mlp->nitems * sizeof (struct pre_sysdep_message));
+  sysdep_msg_arr = XNMALLOC (mlp->nitems, struct pre_sysdep_message);
   n_sysdep_segments = 0;
   sysdep_segments = NULL;
   have_outdigits = false;
@@ -192,7 +189,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
       /* Concatenate mp->msgctxt and mp->msgid into msgctid.  */
       msgctlen = (mp->msgctxt != NULL ? strlen (mp->msgctxt) + 1 : 0);
-      msgctid = (char *) xmalloc (msgctlen + strlen (mp->msgid) + 1);
+      msgctid = XNMALLOC (msgctlen + strlen (mp->msgid) + 1, char);
       if (mp->msgctxt != NULL)
        {
          memcpy (msgctid, mp->msgctxt, msgctlen - 1);
@@ -274,8 +271,9 @@ write_table (FILE *output_file, message_list_ty *mlp)
            {
              struct pre_sysdep_string *pre =
                (struct pre_sysdep_string *)
-               xmalloc (sizeof (struct pre_sysdep_string)
-                        + nintervals[m] * sizeof (struct pre_segment_pair));
+               xmalloc (xsum (sizeof (struct pre_sysdep_string),
+                              xtimes (nintervals[m],
+                                      sizeof (struct pre_segment_pair))));
              const char *str;
              size_t str_len;
              size_t lastpos;
@@ -436,14 +434,12 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* Offset of table for original string offsets.  */
   header.orig_tab_offset = offset;
   offset += nstrings * sizeof (struct string_desc);
-  orig_tab =
-    (struct string_desc *) xmalloc (nstrings * sizeof (struct string_desc));
+  orig_tab = XNMALLOC (nstrings, struct string_desc);
 
   /* Offset of table for translated string offsets.  */
   header.trans_tab_offset = offset;
   offset += nstrings * sizeof (struct string_desc);
-  trans_tab =
-    (struct string_desc *) xmalloc (nstrings * sizeof (struct string_desc));
+  trans_tab = XNMALLOC (nstrings, struct string_desc);
 
   /* Size of hash table.  */
   header.hash_tab_size = hash_tab_size;
@@ -556,7 +552,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
       /* Here output_file is at position header.hash_tab_offset.  */
 
       /* Allocate room for the hashing table to be written out.  */
-      hash_tab = (nls_uint32 *) xmalloc (hash_tab_size * sizeof (nls_uint32));
+      hash_tab = XNMALLOC (hash_tab_size, nls_uint32);
       memset (hash_tab, '\0', hash_tab_size * sizeof (nls_uint32));
 
       /* Insert all value in the hash table, following the algorithm described
@@ -601,8 +597,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
       /* Here output_file is at position header.sysdep_segments_offset.  */
 
       sysdep_segments_tab =
-       (struct sysdep_segment *)
-       xmalloc (n_sysdep_segments * sizeof (struct sysdep_segment));
+       XNMALLOC (n_sysdep_segments, struct sysdep_segment);
       for (i = 0; i < n_sysdep_segments; i++)
        {
          offset = roundup (offset, alignment);
@@ -624,8 +619,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
       free (sysdep_segments_tab);
 
-      sysdep_tab =
-       (nls_uint32 *) xmalloc (n_sysdep_strings * sizeof (nls_uint32));
+      sysdep_tab = XNMALLOC (n_sysdep_strings, nls_uint32);
       stoffset = sysdep_tab_offset;
 
       for (m = 0; m < 2; m++)
index 2d8b49d6e43a6c3ba961938ca83e032917a6c999..4db0972a39f07328ba60aed02a76c7339ac079b5 100644 (file)
@@ -536,8 +536,8 @@ wrap (const message_ty *mp, FILE *fp, const char *line_prefix, int extra_indent,
                }
            }
        }
-      portion = (char *) xmalloc (portion_len);
-      overrides = (char *) xmalloc (portion_len);
+      portion = XNMALLOC (portion_len, char);
+      overrides = XNMALLOC (portion_len, char);
       memset (overrides, UC_BREAK_UNDEFINED, portion_len);
       for (ep = s, pp = portion, op = overrides; ep < es; ep++)
        {
@@ -663,7 +663,7 @@ internationalized messages should not contain the `\\%c' escape sequence"),
       if (es > s && es[-1] == '\n')
        overrides[portion_len - 2] = UC_BREAK_PROHIBITED;
 
-      linebreaks = (char *) xmalloc (portion_len);
+      linebreaks = XNMALLOC (portion_len, char);
 
       /* Subsequent lines after a break are all indented.
         See INDENT-S.  */
index 8406a92628e3aa1641f1c7abafa3c1ef871195cd..79bd0fb7034fbc242937d04d868b1ec02afaaf77 100644 (file)
@@ -76,7 +76,7 @@ conv_to_java (const char *string)
       }
   }
 
-  result = (char *) xmalloc (length + 1);
+  result = XNMALLOC (length + 1, char);
 
   {
     char *newstr = result;
index b32ae30ffd792eac5fdc510fcd9b3521183c80b3..96fd04c2a190b19d70e5b75cfbae7c19cd5f389d 100644 (file)
@@ -1,5 +1,5 @@
 /* Writing Qt .qm files.
-   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -290,7 +290,7 @@ conv_to_iso_8859_1 (const char *string)
   const char *str = string;
   const char *str_limit = string + length;
   /* Conversion to ISO-8859-1 can only reduce the number of bytes.  */
-  char *result = (char *) xmalloc (length + 1);
+  char *result = XNMALLOC (length + 1, char);
   char *q = result;
 
   while (str < str_limit)
@@ -318,7 +318,7 @@ conv_to_utf16 (const char *string, size_t *sizep)
   const char *str = string;
   const char *str_limit = string + length;
   /* Conversion to UTF-16 can at most double the number of bytes.  */
-  unsigned short *result = (unsigned short *) xmalloc (2 * length);
+  unsigned short *result = XNMALLOC (length, unsigned short);
   unsigned short *q = result;
 
   while (str < str_limit)
@@ -518,12 +518,10 @@ write_qm (FILE *output_file, message_list_ty *mlp)
        {
          struct list_cell { const char *context; struct list_cell *next; };
          struct list_cell *list_memory =
-           (struct list_cell *)
-           xmalloc (table_size * sizeof (struct list_cell));
+           XNMALLOC (table_size, struct list_cell);
          struct list_cell *freelist;
          struct bucket { struct list_cell *head; struct list_cell **tail; };
-         struct bucket *buckets =
-           (struct bucket *) xmalloc (table_size * sizeof (struct bucket));
+         struct bucket *buckets = XNMALLOC (table_size, struct bucket);
          size_t i;
 
          freelist = list_memory;
index d47a2af4283cb6e51e0d3d3aab3f94238adf0063..3bc40a57223995694bb0ef6b51bae33a837c7492 100644 (file)
@@ -180,7 +180,7 @@ static inline void
 init_token (struct token *tp)
 {
   tp->allocated = 10;
-  tp->chars = (char *) xmalloc (tp->allocated * sizeof (char));
+  tp->chars = XNMALLOC (tp->allocated, char);
   tp->charcount = 0;
 }
 
@@ -424,7 +424,7 @@ string_of_object (const struct object *op)
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
   n = op->token->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   memcpy (str, op->token->chars, n);
   str[n] = '\0';
   return str;
@@ -856,7 +856,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
 
        case '"':
          {
-           op->token = (struct token *) xmalloc (sizeof (struct token));
+           op->token = XMALLOC (struct token);
            init_token (op->token);
            op->line_number_at_start = line_number;
            for (;;)
@@ -1193,7 +1193,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
          {
            bool symbol;
 
-           op->token = (struct token *) xmalloc (sizeof (struct token));
+           op->token = XMALLOC (struct token);
            symbol = read_token (op->token, c);
            if (symbol)
              {
index f10b8450605870ba872dcdf3e281eb0ad1b40194..1e7de2202693476c01de25ac8f95db75c4d9dcc5 100644 (file)
@@ -182,7 +182,7 @@ static inline void
 init_token (struct token *tp)
 {
   tp->allocated = 10;
-  tp->chars = (char *) xmalloc (tp->allocated * sizeof (char));
+  tp->chars = XNMALLOC (tp->allocated, char);
   tp->charcount = 0;
 }
 
@@ -504,7 +504,7 @@ string_of_object (const struct object *op)
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
   n = op->token->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   memcpy (str, op->token->chars, n);
   str[n] = '\0';
   return str;
@@ -792,7 +792,7 @@ read_object (struct object *op, flag_context_ty outer_context)
 
        case '"':
          {
-           op->token = (struct token *) xmalloc (sizeof (struct token));
+           op->token = XMALLOC (struct token);
            init_token (op->token);
            op->line_number_at_start = line_number;
            for (;;)
@@ -1047,7 +1047,7 @@ read_object (struct object *op, flag_context_ty outer_context)
          {
            bool symbol;
 
-           op->token = (struct token *) xmalloc (sizeof (struct token));
+           op->token = XMALLOC (struct token);
            symbol = read_token (op->token, &c);
            if (op->token->charcount == 1 && op->token->chars[0] == '.')
              {
index 40460106ef5b3c812ec4a2a3858dc546a5ae3f7e..49f63fb62ac670889a589594d6f2301e7ae709bc 100644 (file)
@@ -154,7 +154,7 @@ x_lisp_keyword (const char *name)
 
       /* Uppercase it.  */
       len = end - name;
-      symname = (char *) xmalloc (len);
+      symname = XNMALLOC (len, char);
       for (i = 0; i < len; i++)
        symname[i] =
          (name[i] >= 'a' && name[i] <= 'z' ? name[i] - 'a' + 'A' : name[i]);
@@ -368,8 +368,7 @@ static inline void
 init_token (struct token *tp)
 {
   tp->allocated = 10;
-  tp->chars =
-    (struct token_char *) xmalloc (tp->allocated * sizeof (struct token_char));
+  tp->chars = XNMALLOC (tp->allocated, struct token_char);
   tp->charcount = 0;
 }
 
@@ -922,7 +921,7 @@ string_of_object (const struct object *op)
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
   n = op->token->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   q = str;
   for (p = op->token->chars; n > 0; p++, n--)
     *q++ = p->ch;
@@ -966,7 +965,7 @@ read_object (struct object *op, flag_context_ty outer_context)
        case syntax_multi_esc:
        case syntax_constituent:
          /* Start reading a token.  */
-         op->token = (struct token *) xmalloc (sizeof (struct token));
+         op->token = XMALLOC (struct token);
          read_token (op->token, &curr);
          last_non_comment_line = line_number;
 
@@ -1168,7 +1167,7 @@ read_object (struct object *op, flag_context_ty outer_context)
 
            case '"':
              {
-               op->token = (struct token *) xmalloc (sizeof (struct token));
+               op->token = XMALLOC (struct token);
                init_token (op->token);
                op->line_number_at_start = line_number;
                for (;;)
index 488692633aa84311d4ddbc8047adf3789816d735..7fff57b79dd153fbc00a32263cc222b741689eef 100644 (file)
@@ -286,7 +286,7 @@ get_here_document (const char *delimiter)
   /* Allocate the initial buffer.  Later on, bufmax > 0.  */
   if (bufmax == 0)
     {
-      buffer = (char *) xmalloc (1);
+      buffer = XNMALLOC (1, char);
       buffer[0] = '\0';
       bufmax = 1;
     }
@@ -636,7 +636,7 @@ extract_quotelike_pass1 (int delim)
      statically.  Also alloca() is inappropriate due to limited stack
      size on some platforms.  So we use malloc().  */
   int bufmax = 10;
-  char *buffer = (char *) xmalloc (bufmax);
+  char *buffer = XNMALLOC (bufmax, char);
   int bufpos = 0;
   bool nested = true;
   int counter_delim;
@@ -1093,7 +1093,7 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
                      char *name;
                      unsigned int unicode;
 
-                     name = (char *) xmalloc (end - (crs + 1) + 1);
+                     name = XNMALLOC (end - (crs + 1) + 1, char);
                      memcpy (name, crs + 1, end - (crs + 1));
                      name[end - (crs + 1)] = '\0';
 
@@ -2624,7 +2624,7 @@ x_perl_lex (message_list_ty *mlp)
 
   if (!tp)
     {
-      tp = (token_ty *) xmalloc (sizeof (token_ty));
+      tp = XMALLOC (token_ty);
       x_perl_prelex (mlp, tp);
 #if DEBUG_PERL
       fprintf (stderr, "%s:%d: x_perl_prelex returned %s\n",
index 5142802d4ce88ce729a83d8e4b2c45a17bdbbf74..d3eda33e953febe8cb9c00ecc72b454bfd44cee0 100644 (file)
@@ -86,7 +86,7 @@ extract_add_message (default_catalog_reader_ty *this,
 
            charsetstr += strlen ("charset=");
            len = strcspn (charsetstr, " \t\n");
-           charset = (char *) xmalloc (len + 1);
+           charset = XNMALLOC (len + 1, char);
            memcpy (charset, charsetstr, len);
            charset[len] = '\0';
 
@@ -196,7 +196,7 @@ extract (FILE *fp,
                      len1 = charsetstr - header;
                      len2 = strlen (header_charset);
                      len3 = (header + strlen (header)) - (charsetstr + len);
-                     new_header = (char *) xmalloc (len1 + len2 + len3 + 1);
+                     new_header = XNMALLOC (len1 + len2 + len3 + 1, char);
                      memcpy (new_header, header, len1);
                      memcpy (new_header + len1, header_charset, len2);
                      memcpy (new_header + len1 + len2, charsetstr + len, len3 + 1);
index 325f7503b59b891d67177d8d9971882d731af973..17f6b586166ce51539093c4ccaee2debf649a56d 100644 (file)
@@ -664,7 +664,7 @@ try_to_extract_coding (const char *comment)
                {
                  /* Extract the encoding string.  */
                  size_t encoding_len = encoding_end - encoding_start;
-                 char *encoding = (char *) xmalloc (encoding_len + 1);
+                 char *encoding = XNMALLOC (encoding_len + 1, char);
 
                  memcpy (encoding, encoding_start, encoding_len);
                  encoding[encoding_len] = '\0';
index 6b7641d5baa2745831eee02908fd2de373e218bd..419e9787fd1362191f92c2c238ef40c7276f2eee 100644 (file)
@@ -206,7 +206,7 @@ static inline void
 init_token (struct token *tp)
 {
   tp->allocated = 10;
-  tp->chars = (char *) xmalloc (tp->allocated * sizeof (char));
+  tp->chars = XNMALLOC (tp->allocated, char);
   tp->charcount = 0;
 }
 
@@ -669,7 +669,7 @@ string_of_object (const struct object *op)
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
   n = op->token->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   memcpy (str, op->token->chars, n);
   str[n] = '\0';
   return str;
@@ -977,7 +977,7 @@ read_object (struct object *op, flag_context_ty outer_context)
              case '{':
                /* Symbol with multiple escapes: #{...}#  */
                {
-                 op->token = (struct token *) xmalloc (sizeof (struct token));
+                 op->token = XMALLOC (struct token);
 
                  init_token (op->token);
 
@@ -1078,7 +1078,7 @@ read_object (struct object *op, flag_context_ty outer_context)
 
        case '"':
          {
-           op->token = (struct token *) xmalloc (sizeof (struct token));
+           op->token = XMALLOC (struct token);
            init_token (op->token);
            op->line_number_at_start = line_number;
            for (;;)
@@ -1146,7 +1146,7 @@ read_object (struct object *op, flag_context_ty outer_context)
        case '5': case '6': case '7': case '8': case '9':
        case '+': case '-': case '.':
          /* Read a number or symbol token.  */
-         op->token = (struct token *) xmalloc (sizeof (struct token));
+         op->token = XMALLOC (struct token);
          read_token (op->token, c);
          if (op->token->charcount == 1 && op->token->chars[0] == '.')
            {
@@ -1172,7 +1172,7 @@ read_object (struct object *op, flag_context_ty outer_context)
        case ':':
        default:
          /* Read a symbol token.  */
-         op->token = (struct token *) xmalloc (sizeof (struct token));
+         op->token = XMALLOC (struct token);
          read_token (op->token, c);
          op->type = t_symbol;
          last_non_comment_line = line_number;
index 68c3d2820497bf4a5837dfea47b41f0345722257..a2c932de348d0d844b6a4e394ba150041c277065 100644 (file)
@@ -244,7 +244,7 @@ static inline void
 init_token (struct token *tp)
 {
   tp->allocated = 10;
-  tp->chars = (char *) xmalloc (tp->allocated * sizeof (char));
+  tp->chars = XNMALLOC (tp->allocated, char);
   tp->charcount = 0;
 }
 
@@ -274,7 +274,7 @@ string_of_token (const struct token *tp)
   int n;
 
   n = tp->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   memcpy (str, tp->chars, n);
   str[n] = '\0';
   return str;
@@ -465,7 +465,7 @@ string_of_word (const struct word *wp)
   if (!(wp->type == t_string))
     abort ();
   n = wp->token->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   memcpy (str, wp->token->chars, n);
   str[n] = '\0';
   return str;
@@ -807,7 +807,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
     }
 
   wp->type = t_string;
-  wp->token = (struct token *) xmalloc (sizeof (struct token));
+  wp->token = XMALLOC (struct token);
   init_token (wp->token);
   wp->line_number_at_start = line_number;
   all_unquoted_digits = true;
index 371baabefb0c0e7984ebc6a8243226bc7325d5bd..87ef9abafc814857a3e85e55af8e85f13b788dde 100644 (file)
@@ -326,7 +326,7 @@ phase2_get (token_ty *tp)
              case '@':
              case '?':
              case '%':
-               name = (char *) xmalloc (3);
+               name = XNMALLOC (3, char);
                name[0] = c;
                name[1] = c2;
                name[2] = '\0';
@@ -337,7 +337,7 @@ phase2_get (token_ty *tp)
                phase1_ungetc (c2);
                break;
              }
-           name = (char *) xmalloc (2);
+           name = XNMALLOC (2, char);
            name[0] = c;
            name[1] = '\0';
            tp->type = token_type_symbol;
index 9e09a06f821d35862b4672cac9d3d4a3edd6d412..575da97d1113684ce4b9d021d5cb325375e08f3a 100644 (file)
@@ -335,7 +335,7 @@ static inline void
 init_token (struct token *tp)
 {
   tp->allocated = 10;
-  tp->chars = (char *) xmalloc (tp->allocated * sizeof (char));
+  tp->chars = XNMALLOC (tp->allocated, char);
   tp->charcount = 0;
 }
 
@@ -453,7 +453,7 @@ string_of_word (const struct word *wp)
   if (!(wp->type == t_string))
     abort ();
   n = wp->token->charcount;
-  str = (char *) xmalloc (n + 1);
+  str = XNMALLOC (n + 1, char);
   memcpy (str, wp->token->chars, n);
   str[n] = '\0';
   return str;
@@ -781,7 +781,7 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
     }
 
   wp->type = t_string;
-  wp->token = (struct token *) xmalloc (sizeof (struct token));
+  wp->token = XMALLOC (struct token);
   init_token (wp->token);
   wp->line_number_at_start = line_number;
 
index 7157f832fe675c8ece752c1beb45bd65107f6c0a..4d09321a97529522deb31d75a4f8943634dce130 100644 (file)
@@ -44,6 +44,7 @@
 #include "basename.h"
 #include "xerror.h"
 #include "xvasprintf.h"
+#include "xsize.h"
 #include "xalloc.h"
 #include "xallocsa.h"
 #include "c-strstr.h"
@@ -1055,7 +1056,7 @@ split_keywordspec (const char *spec,
              if (p > spec && (p[-1] == ',' || p[-1] == ':'))
                {
                  size_t xcomment_len = xcomment_end - xcomment_start;
-                 char *xcomment = (char *) xmalloc (xcomment_len + 1);
+                 char *xcomment = XNMALLOC (xcomment_len + 1, char);
 
                  memcpy (xcomment, xcomment_start, xcomment_len);
                  xcomment[xcomment_len] = '\0';
@@ -1124,8 +1125,7 @@ insert_keyword_callshape (hash_table *table,
   if (hash_find_entry (table, keyword, keyword_len, &old_value))
     {
       /* Create a one-element 'struct callshapes'.  */
-      struct callshapes *shapes =
-       (struct callshapes *) xmalloc (sizeof (struct callshapes));
+      struct callshapes *shapes = XMALLOC (struct callshapes);
       shapes->nshapes = 1;
       shapes->shapes[0] = *shape;
       keyword =
@@ -1164,8 +1164,9 @@ insert_keyword_callshape (hash_table *table,
          /* Replace the existing 'struct callshapes' with a new one.  */
          struct callshapes *shapes =
            (struct callshapes *)
-           xmalloc (sizeof (struct callshapes)
-                    + old_shapes->nshapes * sizeof (struct callshape));
+           xmalloc (xsum (sizeof (struct callshapes),
+                          xtimes (old_shapes->nshapes,
+                                  sizeof (struct callshape))));
 
          shapes->keyword = old_shapes->keyword;
          shapes->keyword_len = old_shapes->keyword_len;
@@ -1316,8 +1317,7 @@ flag_context_list_table_insert (flag_context_list_table_ty *table,
     if (hash_find_entry (table, name_start, name_end - name_start, &entry) != 0)
       {
        /* Create new hash table entry.  */
-       flag_context_list_ty *list =
-         (flag_context_list_ty *) xmalloc (sizeof (flag_context_list_ty));
+       flag_context_list_ty *list = XMALLOC (flag_context_list_ty);
        list->argnum = argnum;
        memset (&list->flags, '\0', sizeof (list->flags));
        switch (index)
@@ -1366,8 +1366,7 @@ flag_context_list_table_insert (flag_context_list_table_ty *table,
        else if (lastp != NULL)
          {
            /* Add a new list entry for this argument number.  */
-           list =
-             (flag_context_list_ty *) xmalloc (sizeof (flag_context_list_ty));
+           list = XMALLOC (flag_context_list_ty);
            list->argnum = argnum;
            memset (&list->flags, '\0', sizeof (list->flags));
            switch (index)
@@ -1392,8 +1391,7 @@ flag_context_list_table_insert (flag_context_list_table_ty *table,
               of the list.  Since we don't have an API for replacing the
               value of a key in the hash table, we have to copy the first
               list element.  */
-           flag_context_list_ty *copy =
-             (flag_context_list_ty *) xmalloc (sizeof (flag_context_list_ty));
+           flag_context_list_ty *copy = XMALLOC (flag_context_list_ty);
            *copy = *list;
 
            list->argnum = argnum;
@@ -1683,8 +1681,7 @@ savable_comment_add (const char *str)
 {
   if (savable_comment == NULL)
     {
-      savable_comment =
-       (refcounted_string_list_ty *) xmalloc (sizeof (*savable_comment));
+      savable_comment = XMALLOC (refcounted_string_list_ty);
       savable_comment->refcount = 1;
       string_list_init (&savable_comment->contents);
     }
@@ -1697,8 +1694,7 @@ savable_comment_add (const char *str)
       savable_comment->refcount--;
       oldcontents = &savable_comment->contents;
 
-      savable_comment =
-       (refcounted_string_list_ty *) xmalloc (sizeof (*savable_comment));
+      savable_comment = XMALLOC (refcounted_string_list_ty);
       savable_comment->refcount = 1;
       string_list_init (&savable_comment->contents);
       for (i = 0; i < oldcontents->nitems; i++)
@@ -2239,7 +2235,7 @@ remember_a_message_plural (message_ty *mp, char *string,
       else
        msgstr1 = "";
       msgstr1_len = strlen (msgstr1) + 1;
-      msgstr = (char *) xmalloc (mp->msgstr_len + msgstr1_len);
+      msgstr = XNMALLOC (mp->msgstr_len + msgstr1_len, char);
       memcpy (msgstr, mp->msgstr, mp->msgstr_len);
       memcpy (msgstr + mp->msgstr_len, msgstr1, msgstr1_len);
       mp->msgstr = msgstr;
@@ -2327,8 +2323,9 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes)
     {
       struct arglist_parser *ap =
        (struct arglist_parser *)
-       xmalloc (sizeof (struct arglist_parser)
-                + (shapes->nshapes - 1) * sizeof (struct partial_call));
+       xmalloc (xsum (sizeof (struct arglist_parser),
+                      xtimes (shapes->nshapes - 1,
+                              sizeof (struct partial_call))));
       size_t i;
 
       ap->mlp = mlp;
@@ -2370,8 +2367,8 @@ arglist_parser_clone (struct arglist_parser *ap)
 {
   struct arglist_parser *copy =
     (struct arglist_parser *)
-    xmalloc (sizeof (struct arglist_parser) - sizeof (struct partial_call)
-            + ap->nalternatives * sizeof (struct partial_call));
+    xmalloc (xsum (sizeof (struct arglist_parser) - sizeof (struct partial_call),
+                  xtimes (ap->nalternatives, sizeof (struct partial_call))));
   size_t i;
 
   copy->mlp = ap->mlp;
@@ -2649,7 +2646,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
              else
                {
                  size_t ctxt_len = separator - best_cp->msgid;
-                 char *ctxt = (char *) xmalloc (ctxt_len + 1);
+                 char *ctxt = XNMALLOC (ctxt_len + 1, char);
 
                  memcpy (ctxt, best_cp->msgid, ctxt_len);
                  ctxt[ctxt_len] = '\0';
@@ -2674,7 +2671,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
              else
                {
                  size_t ctxt_len = separator - best_cp->msgid_plural;
-                 char *ctxt = (char *) xmalloc (ctxt_len + 1);
+                 char *ctxt = XNMALLOC (ctxt_len + 1, char);
 
                  memcpy (ctxt, best_cp->msgid_plural, ctxt_len);
                  ctxt[ctxt_len] = '\0';
@@ -2856,7 +2853,7 @@ finalize_header (msgdomain_list_ty *mdlp)
            if (insertpos == 0 || header->msgstr[insertpos-1] == '\n')
              suffix++;
            suffix_len = strlen (suffix);
-           new_msgstr = (char *) xmalloc (header->msgstr_len + suffix_len);
+           new_msgstr = XNMALLOC (header->msgstr_len + suffix_len, char);
            memcpy (new_msgstr, header->msgstr, insertpos);
            memcpy (new_msgstr + insertpos, suffix, suffix_len);
            memcpy (new_msgstr + insertpos + suffix_len,
index 5f814fefe9dcc5ea287d64426989c4f628b2b2d6..bf35519384159c337ebb0d24958eb5219fecb011 100644 (file)
@@ -1,3 +1,8 @@
+2006-11-03  Bruno Haible  <bruno@clisp.org>
+
+       Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
+       * tstgettext.c (expand_escape): Use XNMALLOC instead of xmalloc.
+
 2006-10-26  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.16 released.
index b6220a28ab4768db4e2d5ddcf2e63c910ec1e378..ce83b120dd8af41aa4a5069f4de73fdfc13acd80 100644 (file)
@@ -327,7 +327,7 @@ expand_escape (const char *str)
       ++cp;
     }
 
-  retval = (char *) xmalloc (strlen (str));
+  retval = XNMALLOC (strlen (str), char);
 
   rp = retval + (cp - str);
   memcpy (retval, str, cp - str);
index fe50363faaac99f7ee72eb5243ab36e68a8f9bba..a9237a371fb0f7a8a204bc0737569aec6c53eb0d 100644 (file)
@@ -1,3 +1,14 @@
+2006-11-03  Bruno Haible  <bruno@clisp.org>
+
+       * lib/xalloc.h (XMALLOC, XNMALLOC, XZALLOC, XCALLOC): New macros.
+       (xnboundedmalloc): New inline function.
+       * lib/fstrcmp.c (fstrcmp): Use xnmalloc instead of xmalloc.
+       * lib/hash.c (hash_init, resize): Use XCALLOC instead of xcalloc.
+       * lib/propername.c (proper_name, proper_name_utf8): Use XNMALLOC
+       instead of xmalloc.
+       * lib/xgetcwd.c (xgetcwd): Use XNMALLOC instead of xmalloc.
+       * lib/xstrdup.c (xstrdup): Likewise.
+
 2006-11-06  Bruno Haible  <bruno@clisp.org>
 
        * lib/getopt_.h.diff: Update.
index bfcd7a4fd18ff50ecb123cb8966b2fbb81386bbd..bfe3e7981193dccb6efd8dc879a82ff023e8d765 100644 (file)
@@ -647,7 +647,7 @@ fstrcmp (const char *string1, const char *string2)
         to be preserved.  */
       if (buffer != NULL)
        free (buffer);
-      buffer = (int *) xmalloc (bufmax * (2 * sizeof (int)));
+      buffer = (int *) xnmalloc (bufmax, 2 * sizeof (int));
       gl_tls_set (buffer_key, buffer);
       gl_tls_set (bufmax_key, (void *) (uintptr_t) bufmax);
     }
index abc3a42f8cf62da96506cd36f74607e208306cdc..6c6aac69a8b006932952d13a2b8d994e6b935bc1 100644 (file)
@@ -96,7 +96,7 @@ hash_init (hash_table *htab, unsigned long int init_size)
   htab->size = init_size;
   htab->filled = 0;
   htab->first = NULL;
-  htab->table = (hash_entry *) xcalloc (init_size + 1, sizeof (hash_entry));
+  htab->table = XCALLOC (init_size + 1, hash_entry);
 
   obstack_init (&htab->mem_pool);
 
@@ -245,7 +245,7 @@ resize (hash_table *htab)
   htab->size = next_prime (htab->size * 2);
   htab->filled = 0;
   htab->first = NULL;
-  htab->table = (hash_entry *) xcalloc (1 + htab->size, sizeof (hash_entry));
+  htab->table = XCALLOC (1 + htab->size, hash_entry);
 
   for (idx = 1; idx <= old_size; ++idx)
     if (table[idx].used)
index 0eda923a4fe7ebeb7d89bbfaa9f6350481541ae2..7c58d04bf55518486af54c0e87e400abfc44382a 100644 (file)
@@ -54,7 +54,7 @@ proper_name (const char *name)
        {
          /* Return "TRANSLATION (NAME)".  */
          char *result =
-           (char *) xmalloc (strlen (translation) + 2 + strlen (name) + 1 + 1);
+           XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char);
 
          sprintf (result, "%s (%s)", translation, name);
          return result;
@@ -93,7 +93,7 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8)
      || _LIBICONV_VERSION >= 0x0105
       {
        size_t len = strlen (locale_code);
-       char *locale_code_translit = (char *) xmalloc (len + 10 + 1);
+       char *locale_code_translit = XNMALLOC (len + 10 + 1, char);
        memcpy (locale_code_translit, locale_code, len);
        memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1);
 
@@ -136,7 +136,7 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8)
        {
          /* Return "TRANSLATION (NAME)".  */
          char *result =
-           (char *) xmalloc (strlen (translation) + 2 + strlen (name) + 1 + 1);
+           XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char);
 
          sprintf (result, "%s (%s)", translation, name);
 
index a044610f520c42d67ebd8d385e180fba2a278f3a..ceb1eb926cac8c3ce4c9b687a3aa4e43f73f1da6 100644 (file)
@@ -67,6 +67,50 @@ extern void xalloc_die (void)
 #endif
      ;
 
+/* In the following macros, T must be an elementary or structure/union or
+   typedef'ed type, or a pointer to such a type.  To apply one of the
+   following macros to a function pointer or array type, you need to typedef
+   it first and use the typedef name.  */
+
+/* Allocate an object of type T dynamically, with error checking.  */
+/* extern T *XMALLOC (typename T); */
+#define XMALLOC(T) \
+  ((T *) xmalloc (sizeof (T)))
+
+/* Allocate memory for NMEMB elements of type T, with error checking.  */
+/* extern T *XNMALLOC (size_t nmemb, typename T); */
+#if HAVE_INLINE
+/* xnmalloc performs a division and multiplication by sizeof (T).  Arrange to
+   perform the division at compile-time and the multiplication with a factor
+   known at compile-time.  */
+# define XNMALLOC(N,T) \
+   ((T *) (sizeof (T) == 1 \
+          ? xmalloc (N) \
+          : xnboundedmalloc(N, (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / sizeof (T), sizeof (T))))
+static inline void *
+xnboundedmalloc (size_t n, size_t bound, size_t s)
+{
+  if (n > bound)
+    xalloc_die ();
+  return xmalloc (n * s);
+}
+#else
+# define XNMALLOC(N,T) \
+   ((T *) (sizeof (T) == 1 ? xmalloc (N) : xnmalloc (N, sizeof (T))))
+#endif
+
+/* Allocate an object of type T dynamically, with error checking,
+   and zero it.  */
+/* extern T *XZALLOC (typename T); */
+#define XZALLOC(T) \
+  ((T *) xzalloc (sizeof (T)))
+
+/* Allocate memory for NMEMB elements of type T, with error checking,
+   and zero it.  */
+/* extern T *XCALLOC (size_t nmemb, typename T); */
+#define XCALLOC(N,T) \
+  ((T *) xcalloc (N, sizeof (T)))
+
 
 /* Defined in xstrdup.c.  */
 
index 566c899c8122871db9f5693ce88a03867b98771e..fbcfc64dcc56871c83fffab264daf46e123baa5f 100644 (file)
@@ -63,7 +63,7 @@ xgetcwd ()
 
   for (;;)
     {
-      char *cwd = (char *) xmalloc (path_max);
+      char *cwd = XNMALLOC (path_max, char);
 
       errno = 0;
       ret = getcwd (cwd, path_max);
index b63af6539beb93e285f7da863a52b9c20cd51d7f..cb3c53be68239d4bcc566448da0092b4a39eecf7 100644 (file)
@@ -27,5 +27,5 @@
 char *
 xstrdup (const char *string)
 {
-  return strcpy ((char *) xmalloc (strlen (string) + 1), string);
+  return strcpy (XNMALLOC (strlen (string) + 1, char), string);
 }