From 556d02696528fbe7eacce1db1fab1e8bb7e6b736 Mon Sep 17 00:00:00 2001 From: jakub Date: Sat, 1 Oct 2005 11:50:10 +0000 Subject: * libgfortran.h (GFC_ITOA_BUF_SIZE, GFC_XTOA_BUF_SIZE, GFC_OTOA_BUF_SIZE, GFC_BTOA_BUF_SIZE): Define. (gfc_itoa, xtoa): Add 2 extra arguments. * runtime/environ.c: Include stdio.h. (check_buffered): Use sprintf. * runtime/error.c: Include assert.h. (gfc_itoa, xtoa): Add 2 extra arguments, avoid using static buffers. (st_printf, st_sprintf): Adjust callers. * io/write.c (otoa, btoa): Add 2 extra arguments, avoid using static buffers. (write_int, write_decimal): Add 2 extra arguments to conv function pointer, adjust caller. (write_integer): Adjust gfc_itoa caller. * io/unit.c (get_array_unit_len): Return 0 rather than NULL. * io/read.c (read_f): Remove spurious pointer dereference. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@104855 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgfortran/io/write.c | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'libgfortran/io/write.c') diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index c1bf78eca3e..b21399ff861 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -29,6 +29,7 @@ the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" +#include #include #include #include @@ -910,11 +911,13 @@ write_float (fnode *f, const char *source, int len) static void write_int (fnode *f, const char *source, int len, - char *(*conv) (GFC_UINTEGER_LARGEST)) + const char *(*conv) (GFC_UINTEGER_LARGEST, char *, size_t)) { GFC_UINTEGER_LARGEST n = 0; int w, m, digits, nzero, nblank; - char *p, *q; + char *p; + const char *q; + char itoa_buf[GFC_BTOA_BUF_SIZE]; w = f->u.integer.w; m = f->u.integer.m; @@ -936,7 +939,7 @@ write_int (fnode *f, const char *source, int len, goto done; } - q = conv (n); + q = conv (n, itoa_buf, sizeof (itoa_buf)); digits = strlen (q); /* Select a width if none was specified. The idea here is to always @@ -988,12 +991,14 @@ write_int (fnode *f, const char *source, int len, static void write_decimal (fnode *f, const char *source, int len, - char *(*conv) (GFC_INTEGER_LARGEST)) + const char *(*conv) (GFC_INTEGER_LARGEST, char *, size_t)) { GFC_INTEGER_LARGEST n = 0; int w, m, digits, nsign, nzero, nblank; - char *p, *q; + char *p; + const char *q; sign_t sign; + char itoa_buf[GFC_BTOA_BUF_SIZE]; w = f->u.integer.w; m = f->u.integer.m; @@ -1020,7 +1025,7 @@ write_decimal (fnode *f, const char *source, int len, n = -n; nsign = sign == SIGN_NONE ? 0 : 1; - q = conv (n); + q = conv (n, itoa_buf, sizeof (itoa_buf)); digits = strlen (q); @@ -1075,56 +1080,51 @@ write_decimal (fnode *f, const char *source, int len, /* Convert unsigned octal to ascii. */ -static char * -otoa (GFC_UINTEGER_LARGEST n) +static const char * +otoa (GFC_UINTEGER_LARGEST n, char *buffer, size_t len) { char *p; + assert (len >= GFC_OTOA_BUF_SIZE); + if (n == 0) - { - scratch[0] = '0'; - scratch[1] = '\0'; - return scratch; - } + return "0"; - p = scratch + SCRATCH_SIZE - 1; - *p-- = '\0'; + p = buffer + GFC_OTOA_BUF_SIZE - 1; + *p = '\0'; while (n != 0) { - *p = '0' + (n & 7); - p--; + *--p = '0' + (n & 7); n >>= 3; } - return ++p; + return p; } /* Convert unsigned binary to ascii. */ -static char * -btoa (GFC_UINTEGER_LARGEST n) +static const char * +btoa (GFC_UINTEGER_LARGEST n, char *buffer, size_t len) { char *p; + assert (len >= GFC_BTOA_BUF_SIZE); + if (n == 0) - { - scratch[0] = '0'; - scratch[1] = '\0'; - return scratch; - } + return "0"; - p = scratch + SCRATCH_SIZE - 1; - *p-- = '\0'; + p = buffer + GFC_BTOA_BUF_SIZE - 1; + *p = '\0'; while (n != 0) { - *p-- = '0' + (n & 1); + *--p = '0' + (n & 1); n >>= 1; } - return ++p; + return p; } @@ -1245,8 +1245,9 @@ write_integer (const char *source, int length) const char *q; int digits; int width; + char itoa_buf[GFC_ITOA_BUF_SIZE]; - q = gfc_itoa (extract_int (source, length)); + q = gfc_itoa (extract_int (source, length), itoa_buf, sizeof (itoa_buf)); switch (length) { -- cgit v1.2.1