+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.
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';
++cp;
}
- retval = (char *) xmalloc (strlen (str));
+ retval = XNMALLOC (strlen (str), char);
rp = retval + (cp - str);
memcpy (retval, str, cp - str);
++cp;
}
- retval = (char *) xmalloc (strlen (str));
+ retval = XNMALLOC (strlen (str), char);
rp = retval + (cp - str);
memcpy (retval, str, cp - str);
+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.
{
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;
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,
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,
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,
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++)
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';
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,
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';
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);
+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.
/* 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
{
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);
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;
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;
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);
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;
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);
+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.
/* 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;
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
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;
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++)
}
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
}
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
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;
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],
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],
{
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;
{
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;
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];
}
/* 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;
}
/* 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;
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]);
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]);
{
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;
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;
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++)
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;
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];
/* Normalize the result. */
normalize_list (spec.list);
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
}
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;
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';
spec.named_arg_count = j;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
}
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;
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;
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';
}
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
format++;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
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;
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],
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],
{
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;
{
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;
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];
}
/* 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;
}
/* 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;
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]);
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]);
{
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;
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;
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++)
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;
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];
/* Normalize the result. */
normalize_list (spec.list);
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
}
*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';
}
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';
}
spec.named_arg_count = j;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
goto bad_format;
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
}
}
- result = (struct spec *) xmalloc (sizeof (struct spec));
+ result = XMALLOC (struct spec);
*result = spec;
return result;
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);
{
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;
{
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;
{
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;
{
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;
/* 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;
/* 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;
}
allocated = len + (len >> 2) + 1;
- result = (char *) xmalloc (allocated);
+ result = XNMALLOC (allocated, char);
length = 0;
for (;;)
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;
}
/* 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]);
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;
}
{
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;
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;
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;
char *result;
len = language_end - locale;
- result = (char *) xmalloc (len + 1);
+ result = XNMALLOC (len + 1, char);
memcpy (result, locale, len);
result[len] = '\0';
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';
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';
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;
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);
{
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]);
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++)
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;
}
/* 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;
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';
}
len += id_len + 2;
}
- new_msgstr = (char *) xmalloc (len);
+ new_msgstr = XNMALLOC (len, char);
np = new_msgstr;
for (;;)
{
/* 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;
/* 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
{
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;
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;
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;
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;
}
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);
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) \
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;
}
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);
| 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;
/* 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';
/* 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';
{
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';
{
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';
/* 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';
}
/* 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)
{
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;
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;
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; )
{
/* 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>
{
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;
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)
{
}
if (terminator)
++len;
- result = (char *) xmalloc (len);
+ result = XNMALLOC (len, char);
pos = 0;
for (j = 0; j < slp->nitems; ++j)
{
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;
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 == '-')
if (hashsize >= best_score)
break;
- bitmap = (char *) xmalloc (hashsize);
+ bitmap = XNMALLOC (hashsize, char);
memset (bitmap, 0, hashsize);
score = 0;
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++)
#include "hash.h"
#include "message.h"
#include "format.h"
+#include "xsize.h"
#include "xalloc.h"
#include "xallocsa.h"
#include "binary-io.h"
/* 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;
/* 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);
{
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;
/* 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;
/* 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
/* 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);
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++)
}
}
}
- 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++)
{
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. */
}
}
- result = (char *) xmalloc (length + 1);
+ result = XNMALLOC (length + 1, char);
{
char *newstr = result;
/* 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
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)
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)
{
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;
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;
}
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;
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 (;;)
{
bool symbol;
- op->token = (struct token *) xmalloc (sizeof (struct token));
+ op->token = XMALLOC (struct token);
symbol = read_token (op->token, c);
if (symbol)
{
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;
}
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;
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 (;;)
{
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] == '.')
{
/* 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]);
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;
}
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;
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;
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 (;;)
/* Allocate the initial buffer. Later on, bufmax > 0. */
if (bufmax == 0)
{
- buffer = (char *) xmalloc (1);
+ buffer = XNMALLOC (1, char);
buffer[0] = '\0';
bufmax = 1;
}
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;
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';
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",
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';
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);
{
/* 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';
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;
}
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;
case '{':
/* Symbol with multiple escapes: #{...}# */
{
- op->token = (struct token *) xmalloc (sizeof (struct token));
+ op->token = XMALLOC (struct token);
init_token (op->token);
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 (;;)
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] == '.')
{
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;
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;
}
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;
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;
}
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;
case '@':
case '?':
case '%':
- name = (char *) xmalloc (3);
+ name = XNMALLOC (3, char);
name[0] = c;
name[1] = c2;
name[2] = '\0';
phase1_ungetc (c2);
break;
}
- name = (char *) xmalloc (2);
+ name = XNMALLOC (2, char);
name[0] = c;
name[1] = '\0';
tp->type = token_type_symbol;
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;
}
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;
}
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;
#include "basename.h"
#include "xerror.h"
#include "xvasprintf.h"
+#include "xsize.h"
#include "xalloc.h"
#include "xallocsa.h"
#include "c-strstr.h"
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';
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 =
/* 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;
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)
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)
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;
{
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);
}
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++)
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;
{
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;
{
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;
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';
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';
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,
+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.
++cp;
}
- retval = (char *) xmalloc (strlen (str));
+ retval = XNMALLOC (strlen (str), char);
rp = retval + (cp - str);
memcpy (retval, str, cp - str);
+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.
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);
}
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);
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)
{
/* 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;
|| _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);
{
/* 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);
#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. */
for (;;)
{
- char *cwd = (char *) xmalloc (path_max);
+ char *cwd = XNMALLOC (path_max, char);
errno = 0;
ret = getcwd (cwd, path_max);
char *
xstrdup (const char *string)
{
- return strcpy ((char *) xmalloc (strlen (string) + 1), string);
+ return strcpy (XNMALLOC (strlen (string) + 1, char), string);
}