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 /libgfortran/runtime | |
parent | 5fd21b6e5e4dde449a048e7d66ecb5ffeb93607b (diff) | |
download | gcc-556d02696528fbe7eacce1db1fab1e8bb7e6b736.tar.gz |
* 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
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/environ.c | 6 | ||||
-rw-r--r-- | libgfortran/runtime/error.c | 66 |
2 files changed, 34 insertions, 38 deletions
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); |