diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2014-05-26 23:56:45 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2014-05-26 23:56:45 +0300 |
commit | d74fd3c72be778a1ff4663bf73443bae771d4ce1 (patch) | |
tree | 3876dc747d154274cf385e6bca409643f21a1cae /libgfortran/io | |
parent | b4fb1c2135318e40127da0194c6239eed3d3c4d6 (diff) | |
download | gcc-d74fd3c72be778a1ff4663bf73443bae771d4ce1.zip gcc-d74fd3c72be778a1ff4663bf73443bae771d4ce1.tar.gz gcc-d74fd3c72be778a1ff4663bf73443bae771d4ce1.tar.bz2 |
Introduce xrealloc, use it.
2014-05-26 Janne Blomqvist <jb@gcc.gnu.org>
* libgfortran.h (xrealloc): New prototype.
* runtime/memory.c (xrealloc): New function.
* io/fbuf.c (fbuf_alloc): Use xrealloc.
* io/list_read.c (push_char_default): Likewise.
(push_char4): Likewise.
From-SVN: r210948
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/fbuf.c | 5 | ||||
-rw-r--r-- | libgfortran/io/list_read.c | 15 |
2 files changed, 6 insertions, 14 deletions
diff --git a/libgfortran/io/fbuf.c b/libgfortran/io/fbuf.c index 170ce97..e24da62 100644 --- a/libgfortran/io/fbuf.c +++ b/libgfortran/io/fbuf.c @@ -121,10 +121,7 @@ fbuf_alloc (gfc_unit * u, int len) { /* Round up to nearest multiple of the current buffer length. */ newlen = ((u->fbuf->pos + len) / u->fbuf->len + 1) * u->fbuf->len; - dest = realloc (u->fbuf->buf, newlen); - if (dest == NULL) - return NULL; - u->fbuf->buf = dest; + u->fbuf->buf = xrealloc (u->fbuf->buf, newlen); u->fbuf->len = newlen; } diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index 13e38f4..a7e4f88 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -79,7 +79,7 @@ typedef unsigned char uchar; static void push_char_default (st_parameter_dt *dtp, int c) { - char *new; + if (dtp->u.p.saved_string == NULL) { @@ -92,13 +92,11 @@ push_char_default (st_parameter_dt *dtp, int c) if (dtp->u.p.saved_used >= dtp->u.p.saved_length) { dtp->u.p.saved_length = 2 * dtp->u.p.saved_length; - new = realloc (dtp->u.p.saved_string, dtp->u.p.saved_length); - if (new == NULL) - generate_error (&dtp->common, LIBERROR_OS, NULL); - dtp->u.p.saved_string = new; + dtp->u.p.saved_string = + xrealloc (dtp->u.p.saved_string, dtp->u.p.saved_length); // Also this should not be necessary. - memset (new + dtp->u.p.saved_used, 0, + memset (dtp->u.p.saved_string + dtp->u.p.saved_used, 0, dtp->u.p.saved_length - dtp->u.p.saved_used); } @@ -126,10 +124,7 @@ push_char4 (st_parameter_dt *dtp, int c) if (dtp->u.p.saved_used >= dtp->u.p.saved_length) { dtp->u.p.saved_length = 2 * dtp->u.p.saved_length; - new = realloc (p, dtp->u.p.saved_length * sizeof (gfc_char4_t)); - if (new == NULL) - generate_error (&dtp->common, LIBERROR_OS, NULL); - p = new; + p = xrealloc (p, dtp->u.p.saved_length * sizeof (gfc_char4_t)); memset4 (new + dtp->u.p.saved_used, 0, dtp->u.p.saved_length - dtp->u.p.saved_used); |