diff options
author | jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-25 05:48:49 +0000 |
---|---|---|
committer | jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-25 05:48:49 +0000 |
commit | 33123ed70fd7dc8e09a235177ed054dd2d9ad585 (patch) | |
tree | 685cb6240f35fb0058480526772367ef510d1cba /libgfortran/runtime | |
parent | 3414a8bceab3dcebe4a6951abdb85df3ff2f9be0 (diff) | |
download | gcc-33123ed70fd7dc8e09a235177ed054dd2d9ad585.tar.gz |
Use calloc instead of malloc and memset.
2012-03-25 Janne Blomqvist <jb@gcc.gnu.org>
* runtime/memory.c (xcalloc): New function.
* libgfortran.h (xcalloc): New prototype.
* io/list_read.c (push_char): Use xcalloc instead of get_mem and
memset.
(l_push_char): Likewise.
* io/unit.c (insert_unit): Likewise.
(get_internal_unit): Likewise.
* io/unix.c (open_internal): Likewise.
(open_internal4): Likewise.
(fd_to_stream): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@185773 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/memory.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c index a26d9e59efa..044a115c1f5 100644 --- a/libgfortran/runtime/memory.c +++ b/libgfortran/runtime/memory.c @@ -1,5 +1,6 @@ /* Memory management routines. - Copyright 2002, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright 2002, 2005, 2006, 2007, 2009, 2010, 2012 + Free Software Foundation, Inc. Contributed by Paul Brook <paul@nowt.org> This file is part of the GNU Fortran runtime library (libgfortran). @@ -59,3 +60,19 @@ internal_malloc_size (size_t size) return get_mem (size); } + + +/* calloc wrapper that aborts on error. */ + +void * +xcalloc (size_t nmemb, size_t size) +{ + if (nmemb * size == 0) + nmemb = size = 1; + + void *p = calloc (nmemb, size); + if (!p) + os_error ("Allocating cleared memory failed"); + + return p; +} |