diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-10-01 11:50:10 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-10-01 11:50:10 +0000 |
commit | 556d02696528fbe7eacce1db1fab1e8bb7e6b736 (patch) | |
tree | be9e8c61a086ff18a3169c8a58d1c4886f88a747 | |
parent | 5fd21b6e5e4dde449a048e7d66ecb5ffeb93607b (diff) | |
download | ppe42-gcc-556d02696528fbe7eacce1db1fab1e8bb7e6b736.tar.gz ppe42-gcc-556d02696528fbe7eacce1db1fab1e8bb7e6b736.zip |
* 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
-rw-r--r-- | libgfortran/ChangeLog | 21 | ||||
-rw-r--r-- | libgfortran/io/read.c | 2 | ||||
-rw-r--r-- | libgfortran/io/unit.c | 2 | ||||
-rw-r--r-- | libgfortran/io/write.c | 61 | ||||
-rw-r--r-- | libgfortran/libgfortran.h | 9 | ||||
-rw-r--r-- | libgfortran/runtime/environ.c | 6 | ||||
-rw-r--r-- | libgfortran/runtime/error.c | 66 |
7 files changed, 95 insertions, 72 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 07b2e913c7c..3b5abd2d814 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,24 @@ +2005-10-01 Jakub Jelinek <jakub@redhat.com> + + * 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. + 2005-09-30 Janne Blomqvist <jblomqvi@cc.hut.fi> PR 24112 diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c index ec6077ca45e..a3a221ae146 100644 --- a/libgfortran/io/read.c +++ b/libgfortran/io/read.c @@ -621,7 +621,7 @@ read_f (fnode * f, char *dest, int length) case '9': case ' ': ndigits++; - *p++; + p++; w--; break; diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index 586e9edf3d3..b078d87c96a 100644 --- a/libgfortran/io/unit.c +++ b/libgfortran/io/unit.c @@ -261,7 +261,7 @@ get_array_unit_len (gfc_array_char *desc) if (desc->dim[i].stride != stride) { generate_error (ERROR_ARRAY_STRIDE, NULL); - return NULL; + return 0; } stride *= desc->dim[i].ubound; record_count *= desc->dim[i].ubound; 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 <assert.h> #include <string.h> #include <ctype.h> #include <float.h> @@ -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) { diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index ba8261de4e4..49d2c619eee 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -413,10 +413,15 @@ internal_proto(get_args); /* error.c */ -extern char *gfc_itoa (GFC_INTEGER_LARGEST); +#define GFC_ITOA_BUF_SIZE (sizeof (GFC_INTEGER_LARGEST) * 3 + 2) +#define GFC_XTOA_BUF_SIZE (sizeof (GFC_UINTEGER_LARGEST) * 2 + 1) +#define GFC_OTOA_BUF_SIZE (sizeof (GFC_INTEGER_LARGEST) * 3 + 1) +#define GFC_BTOA_BUF_SIZE (sizeof (GFC_INTEGER_LARGEST) * 8 + 1) + +extern const char *gfc_itoa (GFC_INTEGER_LARGEST, char *, size_t); internal_proto(gfc_itoa); -extern char *xtoa (GFC_UINTEGER_LARGEST); +extern const char *xtoa (GFC_UINTEGER_LARGEST, char *, size_t); internal_proto(xtoa); extern void os_error (const char *) __attribute__ ((noreturn)); diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c index e86f2ce5b5c..fb5da2012ad 100644 --- a/libgfortran/runtime/environ.c +++ b/libgfortran/runtime/environ.c @@ -28,6 +28,7 @@ the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" +#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> @@ -580,15 +581,14 @@ init_variables (void) int check_buffered (int n) { - char name[40]; + char name[22 + sizeof (n) * 3]; variable v; int rv; if (options.all_unbuffered) return 0; - strcpy (name, "GFORTRAN_UNBUFFERED_"); - strcat (name, gfc_itoa (n)); + sprintf (name, "GFORTRAN_UNBUFFERED_%d", n); v.name = name; v.value = 2; diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index 7c708e3db4e..60fc56c9d88 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -29,6 +29,7 @@ Boston, MA 02110-1301, USA. */ #include "config.h" +#include <assert.h> #include <stdio.h> #include <stdarg.h> #include <string.h> @@ -63,25 +64,19 @@ iexport_data(filename); unsigned line = 0; iexport_data(line); -/* buffer for integer/ascii conversions. */ -static char buffer[sizeof (GFC_UINTEGER_LARGEST) * 8 + 1]; +/* gfc_itoa()-- Integer to decimal conversion. */ - -/* Returns a pointer to a static buffer. */ - -char * -gfc_itoa (GFC_INTEGER_LARGEST n) +const char * +gfc_itoa (GFC_INTEGER_LARGEST n, char *buffer, size_t len) { int negative; char *p; GFC_UINTEGER_LARGEST t; + assert (len >= GFC_ITOA_BUF_SIZE); + if (n == 0) - { - buffer[0] = '0'; - buffer[1] = '\0'; - return buffer; - } + return "0"; negative = 0; t = n; @@ -91,39 +86,36 @@ gfc_itoa (GFC_INTEGER_LARGEST n) t = -n; /*must use unsigned to protect from overflow*/ } - p = buffer + sizeof (buffer) - 1; - *p-- = '\0'; + p = buffer + GFC_ITOA_BUF_SIZE - 1; + *p = '\0'; while (t != 0) { - *p-- = '0' + (t % 10); + *--p = '0' + (t % 10); t /= 10; } if (negative) - *p-- = '-'; - return ++p; + *--p = '-'; + return p; } -/* xtoa()-- Integer to hexadecimal conversion. Returns a pointer to a - * static buffer. */ +/* xtoa()-- Integer to hexadecimal conversion. */ -char * -xtoa (GFC_UINTEGER_LARGEST n) +const char * +xtoa (GFC_UINTEGER_LARGEST n, char *buffer, size_t len) { int digit; char *p; + assert (len >= GFC_XTOA_BUF_SIZE); + if (n == 0) - { - buffer[0] = '0'; - buffer[1] = '\0'; - return buffer; - } + return "0"; - p = buffer + sizeof (buffer) - 1; - *p-- = '\0'; + p = buffer + GFC_XTOA_BUF_SIZE - 1; + *p = '\0'; while (n != 0) { @@ -131,11 +123,11 @@ xtoa (GFC_UINTEGER_LARGEST n) if (digit > 9) digit += 'A' - '0' - 10; - *p-- = '0' + digit; + *--p = '0' + digit; n >>= 4; } - return ++p; + return p; } @@ -149,8 +141,10 @@ st_printf (const char *format, ...) { int count, total; va_list arg; - char *p, *q; + char *p; + const char *q; stream *s; + char itoa_buf[GFC_ITOA_BUF_SIZE]; total = 0; s = init_error_stream (); @@ -187,7 +181,7 @@ st_printf (const char *format, ...) break; case 'd': - q = gfc_itoa (va_arg (arg, int)); + q = gfc_itoa (va_arg (arg, int), itoa_buf, sizeof (itoa_buf)); count = strlen (q); p = salloc_w (s, &count); @@ -196,7 +190,7 @@ st_printf (const char *format, ...) break; case 'x': - q = xtoa (va_arg (arg, unsigned)); + q = xtoa (va_arg (arg, unsigned), itoa_buf, sizeof (itoa_buf)); count = strlen (q); p = salloc_w (s, &count); @@ -240,8 +234,10 @@ void st_sprintf (char *buffer, const char *format, ...) { va_list arg; - char c, *p; + char c; + const char *p; int count; + char itoa_buf[GFC_ITOA_BUF_SIZE]; va_start (arg, format); @@ -264,7 +260,7 @@ st_sprintf (char *buffer, const char *format, ...) break; case 'd': - p = gfc_itoa (va_arg (arg, int)); + p = gfc_itoa (va_arg (arg, int), itoa_buf, sizeof (itoa_buf)); count = strlen (p); memcpy (buffer, p, count); |