diff options
author | Bruno Haible <bruno@clisp.org> | 2006-11-06 20:15:10 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:14:19 +0200 |
commit | e86f6c583e542d6a1d2d2b5f6bfaa5c155654f0f (patch) | |
tree | 160564919f1fea7fbfa5d4a5fcd294867012ca6a | |
parent | 9484d0c4feb9cc4efe47f69967b406e2b960596b (diff) | |
download | external_gettext-e86f6c583e542d6a1d2d2b5f6bfaa5c155654f0f.zip external_gettext-e86f6c583e542d6a1d2d2b5f6bfaa5c155654f0f.tar.gz external_gettext-e86f6c583e542d6a1d2d2b5f6bfaa5c155654f0f.tar.bz2 |
New macros XMALLOC, XNMALLOC.
74 files changed, 427 insertions, 283 deletions
diff --git a/gettext-runtime/src/ChangeLog b/gettext-runtime/src/ChangeLog index bb52aef..426cd95 100644 --- a/gettext-runtime/src/ChangeLog +++ b/gettext-runtime/src/ChangeLog @@ -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. diff --git a/gettext-runtime/src/envsubst.c b/gettext-runtime/src/envsubst.c index c851267..65f7309 100644 --- a/gettext-runtime/src/envsubst.c +++ b/gettext-runtime/src/envsubst.c @@ -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'; diff --git a/gettext-runtime/src/gettext.c b/gettext-runtime/src/gettext.c index bea3f5a..a491658 100644 --- a/gettext-runtime/src/gettext.c +++ b/gettext-runtime/src/gettext.c @@ -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); diff --git a/gettext-runtime/src/ngettext.c b/gettext-runtime/src/ngettext.c index be021c9..af5c5f2 100644 --- a/gettext-runtime/src/ngettext.c +++ b/gettext-runtime/src/ngettext.c @@ -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); diff --git a/gettext-tools/libgettextpo/ChangeLog b/gettext-tools/libgettextpo/ChangeLog index dc0e352..9ae3c27 100644 --- a/gettext-tools/libgettextpo/ChangeLog +++ b/gettext-tools/libgettextpo/ChangeLog @@ -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. diff --git a/gettext-tools/libgettextpo/gettext-po.c b/gettext-tools/libgettextpo/gettext-po.c index 2a139ae..87df81b 100644 --- a/gettext-tools/libgettextpo/gettext-po.c +++ b/gettext-tools/libgettextpo/gettext-po.c @@ -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); diff --git a/gettext-tools/libgrep/ChangeLog b/gettext-tools/libgrep/ChangeLog index d117aa3..46c8907 100644 --- a/gettext-tools/libgrep/ChangeLog +++ b/gettext-tools/libgrep/ChangeLog @@ -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. diff --git a/gettext-tools/libgrep/m-common.c b/gettext-tools/libgrep/m-common.c index 3bf13a6..1bf9e39 100644 --- a/gettext-tools/libgrep/m-common.c +++ b/gettext-tools/libgrep/m-common.c @@ -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); diff --git a/gettext-tools/libgrep/m-fgrep.c b/gettext-tools/libgrep/m-fgrep.c index 305b997..7aa86ed 100644 --- a/gettext-tools/libgrep/m-fgrep.c +++ b/gettext-tools/libgrep/m-fgrep.c @@ -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; diff --git a/gettext-tools/libgrep/m-regex.c b/gettext-tools/libgrep/m-regex.c index a53c96f..b802a12 100644 --- a/gettext-tools/libgrep/m-regex.c +++ b/gettext-tools/libgrep/m-regex.c @@ -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); diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 537ecab..18ff312 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -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. diff --git a/gettext-tools/src/filter-sr-latin.c b/gettext-tools/src/filter-sr-latin.c index 0af560e..7fa2c9b 100644 --- a/gettext-tools/src/filter-sr-latin.c +++ b/gettext-tools/src/filter-sr-latin.c @@ -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; diff --git a/gettext-tools/src/format-awk.c b/gettext-tools/src/format-awk.c index 3408f3d..8cdbc5a 100644 --- a/gettext-tools/src/format-awk.c +++ b/gettext-tools/src/format-awk.c @@ -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; diff --git a/gettext-tools/src/format-boost.c b/gettext-tools/src/format-boost.c index 70f9d5e..8f1e3cb 100644 --- a/gettext-tools/src/format-boost.c +++ b/gettext-tools/src/format-boost.c @@ -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; diff --git a/gettext-tools/src/format-c.c b/gettext-tools/src/format-c.c index df34701..b953f41 100644 --- a/gettext-tools/src/format-c.c +++ b/gettext-tools/src/format-c.c @@ -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++) diff --git a/gettext-tools/src/format-csharp.c b/gettext-tools/src/format-csharp.c index 2fd7593..e72506e 100644 --- a/gettext-tools/src/format-csharp.c +++ b/gettext-tools/src/format-csharp.c @@ -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; } diff --git a/gettext-tools/src/format-elisp.c b/gettext-tools/src/format-elisp.c index 9e99261..b47a262 100644 --- a/gettext-tools/src/format-elisp.c +++ b/gettext-tools/src/format-elisp.c @@ -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; diff --git a/gettext-tools/src/format-gcc-internal.c b/gettext-tools/src/format-gcc-internal.c index d2a006b..ee15eff 100644 --- a/gettext-tools/src/format-gcc-internal.c +++ b/gettext-tools/src/format-gcc-internal.c @@ -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; diff --git a/gettext-tools/src/format-java.c b/gettext-tools/src/format-java.c index 936297d..38aaaa3 100644 --- a/gettext-tools/src/format-java.c +++ b/gettext-tools/src/format-java.c @@ -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; diff --git a/gettext-tools/src/format-librep.c b/gettext-tools/src/format-librep.c index f761360..c44c968 100644 --- a/gettext-tools/src/format-librep.c +++ b/gettext-tools/src/format-librep.c @@ -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; diff --git a/gettext-tools/src/format-lisp.c b/gettext-tools/src/format-lisp.c index b9b6ad7..4dd6bbf 100644 --- a/gettext-tools/src/format-lisp.c +++ b/gettext-tools/src/format-lisp.c @@ -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; } diff --git a/gettext-tools/src/format-pascal.c b/gettext-tools/src/format-pascal.c index 1d0996a..0857aa4 100644 --- a/gettext-tools/src/format-pascal.c +++ b/gettext-tools/src/format-pascal.c @@ -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; diff --git a/gettext-tools/src/format-perl-brace.c b/gettext-tools/src/format-perl-brace.c index 1d3877b..dfc45ae 100644 --- a/gettext-tools/src/format-perl-brace.c +++ b/gettext-tools/src/format-perl-brace.c @@ -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; } diff --git a/gettext-tools/src/format-perl.c b/gettext-tools/src/format-perl.c index f20c49d..1c92809 100644 --- a/gettext-tools/src/format-perl.c +++ b/gettext-tools/src/format-perl.c @@ -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; diff --git a/gettext-tools/src/format-php.c b/gettext-tools/src/format-php.c index 7ed24c2..601a033 100644 --- a/gettext-tools/src/format-php.c +++ b/gettext-tools/src/format-php.c @@ -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; diff --git a/gettext-tools/src/format-python.c b/gettext-tools/src/format-python.c index 35012e3..e8a973a 100644 --- a/gettext-tools/src/format-python.c +++ b/gettext-tools/src/format-python.c @@ -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; diff --git a/gettext-tools/src/format-qt.c b/gettext-tools/src/format-qt.c index aa51a93..67aad7a 100644 --- a/gettext-tools/src/format-qt.c +++ b/gettext-tools/src/format-qt.c @@ -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; diff --git a/gettext-tools/src/format-scheme.c b/gettext-tools/src/format-scheme.c index b4300c4..78ee865 100644 --- a/gettext-tools/src/format-scheme.c +++ b/gettext-tools/src/format-scheme.c @@ -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; } diff --git a/gettext-tools/src/format-sh.c b/gettext-tools/src/format-sh.c index 176177f..8390e72 100644 --- a/gettext-tools/src/format-sh.c +++ b/gettext-tools/src/format-sh.c @@ -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; diff --git a/gettext-tools/src/format-tcl.c b/gettext-tools/src/format-tcl.c index a8e006c..f98add8 100644 --- a/gettext-tools/src/format-tcl.c +++ b/gettext-tools/src/format-tcl.c @@ -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; diff --git a/gettext-tools/src/format-ycp.c b/gettext-tools/src/format-ycp.c index 8acbf6b..8929cff 100644 --- a/gettext-tools/src/format-ycp.c +++ b/gettext-tools/src/format-ycp.c @@ -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; diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index 1bf0451..b7019f3 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -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; diff --git a/gettext-tools/src/msgexec.c b/gettext-tools/src/msgexec.c index 3af467a..65b02db 100644 --- a/gettext-tools/src/msgexec.c +++ b/gettext-tools/src/msgexec.c @@ -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; diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index 8a15c7f..d0b6339 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -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]); diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index 642bbe4..c1a2dea 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -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; diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index c44439b..a561672 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -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++) diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index 02ffe73..38e0423 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -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 (;;) { diff --git a/gettext-tools/src/msgl-check.c b/gettext-tools/src/msgl-check.c index 4d7a5c1..67ef53c 100644 --- a/gettext-tools/src/msgl-check.c +++ b/gettext-tools/src/msgl-check.c @@ -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; diff --git a/gettext-tools/src/msgl-english.c b/gettext-tools/src/msgl-english.c index 87c6c2a..1106bb7 100644 --- a/gettext-tools/src/msgl-english.c +++ b/gettext-tools/src/msgl-english.c @@ -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; diff --git a/gettext-tools/src/msgl-fsearch.c b/gettext-tools/src/msgl-fsearch.c index fa69f99..a323de5 100644 --- a/gettext-tools/src/msgl-fsearch.c +++ b/gettext-tools/src/msgl-fsearch.c @@ -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; } diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 0a451c2..2482633 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -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); diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index cda1a2f..be0b920 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -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); diff --git a/gettext-tools/src/po-gram-gen.y b/gettext-tools/src/po-gram-gen.y index 61f73f6..6735cd6 100644 --- a/gettext-tools/src/po-gram-gen.y +++ b/gettext-tools/src/po-gram-gen.y @@ -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; diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index 0d88a2b..653d362 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -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'; diff --git a/gettext-tools/src/read-mo.c b/gettext-tools/src/read-mo.c index c6bc9d0..6f2b392 100644 --- a/gettext-tools/src/read-mo.c +++ b/gettext-tools/src/read-mo.c @@ -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) diff --git a/gettext-tools/src/read-properties.c b/gettext-tools/src/read-properties.c index 19fa539..ac02014 100644 --- a/gettext-tools/src/read-properties.c +++ b/gettext-tools/src/read-properties.c @@ -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; diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index c1cb646..a2dd54c 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -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; ) { diff --git a/gettext-tools/src/str-list.c b/gettext-tools/src/str-list.c index 484d9e6..35af5f1 100644 --- a/gettext-tools/src/str-list.c +++ b/gettext-tools/src/str-list.c @@ -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) { diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c index 75f9fee..45e00c5 100644 --- a/gettext-tools/src/write-csharp.c +++ b/gettext-tools/src/write-csharp.c @@ -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 == '-') diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index 6b21646..2f3af25 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -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++) diff --git a/gettext-tools/src/write-mo.c b/gettext-tools/src/write-mo.c index 2ef6810..f5966bb 100644 --- a/gettext-tools/src/write-mo.c +++ b/gettext-tools/src/write-mo.c @@ -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++) diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 2d8b49d..4db0972 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -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. */ diff --git a/gettext-tools/src/write-properties.c b/gettext-tools/src/write-properties.c index 8406a92..79bd0fb 100644 --- a/gettext-tools/src/write-properties.c +++ b/gettext-tools/src/write-properties.c @@ -76,7 +76,7 @@ conv_to_java (const char *string) } } - result = (char *) xmalloc (length + 1); + result = XNMALLOC (length + 1, char); { char *newstr = result; diff --git a/gettext-tools/src/write-qt.c b/gettext-tools/src/write-qt.c index b32ae30..96fd04c 100644 --- a/gettext-tools/src/write-qt.c +++ b/gettext-tools/src/write-qt.c @@ -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; diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index d47a2af..3bc40a5 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -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) { diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index f10b845..1e7de22 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -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] == '.') { diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 4046010..49f63fb 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -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 (;;) diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 4886926..7fff57b 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -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", diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index 5142802..d3eda33 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -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); diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 325f750..17f6b58 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -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'; diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index 6b7641d..419e978 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -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; diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 68c3d28..a2c932d 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -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; diff --git a/gettext-tools/src/x-smalltalk.c b/gettext-tools/src/x-smalltalk.c index 371baab..87ef9ab 100644 --- a/gettext-tools/src/x-smalltalk.c +++ b/gettext-tools/src/x-smalltalk.c @@ -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; diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index 9e09a06..575da97 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -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; diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index 7157f83..4d09321 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -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, diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 5f814fe..bf35519 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -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. diff --git a/gettext-tools/tests/tstgettext.c b/gettext-tools/tests/tstgettext.c index b6220a2..ce83b12 100644 --- a/gettext-tools/tests/tstgettext.c +++ b/gettext-tools/tests/tstgettext.c @@ -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); diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index fe50363..a9237a3 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -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. diff --git a/gnulib-local/lib/fstrcmp.c b/gnulib-local/lib/fstrcmp.c index bfcd7a4..bfe3e79 100644 --- a/gnulib-local/lib/fstrcmp.c +++ b/gnulib-local/lib/fstrcmp.c @@ -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); } diff --git a/gnulib-local/lib/hash.c b/gnulib-local/lib/hash.c index abc3a42..6c6aac6 100644 --- a/gnulib-local/lib/hash.c +++ b/gnulib-local/lib/hash.c @@ -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) diff --git a/gnulib-local/lib/propername.c b/gnulib-local/lib/propername.c index 0eda923..7c58d04 100644 --- a/gnulib-local/lib/propername.c +++ b/gnulib-local/lib/propername.c @@ -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); diff --git a/gnulib-local/lib/xalloc.h b/gnulib-local/lib/xalloc.h index a044610..ceb1eb9 100644 --- a/gnulib-local/lib/xalloc.h +++ b/gnulib-local/lib/xalloc.h @@ -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. */ diff --git a/gnulib-local/lib/xgetcwd.c b/gnulib-local/lib/xgetcwd.c index 566c899..fbcfc64 100644 --- a/gnulib-local/lib/xgetcwd.c +++ b/gnulib-local/lib/xgetcwd.c @@ -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); diff --git a/gnulib-local/lib/xstrdup.c b/gnulib-local/lib/xstrdup.c index b63af65..cb3c53b 100644 --- a/gnulib-local/lib/xstrdup.c +++ b/gnulib-local/lib/xstrdup.c @@ -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); } |