aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/write.c
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2018-01-07 12:17:52 +0200
committerJanne Blomqvist <jb@gcc.gnu.org>2018-01-07 12:17:52 +0200
commitea99ec5bd62c0d14023aac0316f4286193db9434 (patch)
tree36694f3e28c6ca161e719f0dc4e69779533ff1fa /libgfortran/io/write.c
parentc7c9468a6c1e21bb140f62d97d427352d90556bc (diff)
downloadgcc-ea99ec5bd62c0d14023aac0316f4286193db9434.zip
gcc-ea99ec5bd62c0d14023aac0316f4286193db9434.tar.gz
gcc-ea99ec5bd62c0d14023aac0316f4286193db9434.tar.bz2
PR 78534, 83704 Handle large formatted I/O
In order to handle large characters when doing formatted I/O, use size_t and ptrdiff_t for lengths. Compared to the previous patch, based on discussions on IRC use size_t for sizes that don't need to be negative rather than ptrdiff_t everywhere. Regtested on x86_64-pc-linux-gnu, approved as part of the PR 78534 approval, committed to trunk. libgfortran/ChangeLog: 2018-01-07 Janne Blomqvist <jb@gcc.gnu.org> PR fortran/78534 PR fortran/83704 * io/fbuf.c (fbuf_init): Use size_t instead of int for length. (fbuf_debug): Convert debug output to unsigned long. (fbuf_reset): Use ptrdiff_t for return value. (fbuf_alloc): Use size_t for length argument. (fbuf_flush): Handle large buffers. (fbuf_flush_list): Likewise. (fbuf_seek): Use ptrdiff_t for offset and return value. (fbuf_read): Use size_t for length argument. (fbuf_getc_refill): Use size_t to match fbuf_read. * io/fbuf.h (struct fbuf): Use size_t for lengths. (fbuf_init): Use size_t instead of int for length. (fbuf_reset): Use ptrdiff_t for return value. (fbuf_alloc): Use size_t for length argument. (fbuf_seek): Use ptrdiff_t for offset and return value. (fbuf_read): Use size_t for length argument. * io/io.h (read_block_form): Likewise. (read_block_form4): Likewise. (write_block): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_x): Likewise. (write_a): Likewise. (write_a_char4): Likewise. * io/list_read.c (list_formatted_read_scalar): Use size_t to handle large buffers. * io/read.c (read_l): Likewise. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (eat_leading_spaces): Likewise. (next_char): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. (read_x): Likewise. * io/transfer.c (read_sf_internal): Likewise. (read_sf): Likewise. (read_block_form): Likewise. (read_block_form4): Likewise. (write_block): Likewise. (formatted_transfer_scalar_write): Likewise. (next_record_w): Likewise. * io/unix.c (mem_alloc_r): Likewise. (mem_alloc_r4): Likewise. (mem_alloc_w): Likewise. (mem_alloc_w4): Likewise. (mem_read): Likewise. (mem_read4): Likewise. (mem_write): Likewise. (mem_write4): Likewise. (open_internal): Likewise. (open_internal4): Likewise. * io/unix.h (open_internal): Likewise. (open_internal4): Likewise. (mem_alloc_w): Likewise. (mem_alloc_r): Likewise. (mem_alloc_w4): Likewise. (mem_alloc_r4): Likewise. * io/write.c (write_check_cc): Likewise. (write_cc): Likewise. (write_a): Likewise. (write_a_char4): Likewise. From-SVN: r256322
Diffstat (limited to 'libgfortran/io/write.c')
-rw-r--r--libgfortran/io/write.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index ee6b461..8021a1e 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -235,7 +235,7 @@ write_utf8_char4 (st_parameter_dt *dtp, gfc_char4_t *source,
is set to the appropriate size to allocate. */
static void
-write_check_cc (st_parameter_dt *dtp, const char **source, int *alloc_len)
+write_check_cc (st_parameter_dt *dtp, const char **source, size_t *alloc_len)
{
/* Only valid for CARRIAGECONTROL=FORTRAN. */
if (dtp->u.p.current_unit->flags.cc != CC_FORTRAN
@@ -311,7 +311,7 @@ write_check_cc (st_parameter_dt *dtp, const char **source, int *alloc_len)
after the start-of-record string was inserted. */
static char *
-write_cc (st_parameter_dt *dtp, char *p, int *source_len)
+write_cc (st_parameter_dt *dtp, char *p, size_t *source_len)
{
/* Only valid for CARRIAGECONTROL=FORTRAN. */
if (dtp->u.p.current_unit->flags.cc != CC_FORTRAN || source_len == NULL)
@@ -360,14 +360,15 @@ write_cc (st_parameter_dt *dtp, char *p, int *source_len)
}
void
-write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
+
+write_a (st_parameter_dt *dtp, const fnode *f, const char *source, size_t len)
{
- int wlen;
+ size_t wlen;
char *p;
wlen = f->u.string.length < 0
|| (f->format == FMT_G && f->u.string.length == 0)
- ? len : f->u.string.length;
+ ? len : (size_t) f->u.string.length;
#ifdef HAVE_CRLF
/* If this is formatted STREAM IO convert any embedded line feed characters
@@ -376,7 +377,7 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
if (is_stream_io (dtp))
{
const char crlf[] = "\r\n";
- int i, q, bytes;
+ size_t q, bytes;
q = bytes = 0;
/* Write out any padding if needed. */
@@ -389,7 +390,7 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
}
/* Scan the source string looking for '\n' and convert it if found. */
- for (i = 0; i < wlen; i++)
+ for (size_t i = 0; i < wlen; i++)
{
if (source[i] == '\n')
{
@@ -471,14 +472,14 @@ write_a (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
to the UTF-8 encoded string before writing out. */
void
-write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
+write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, size_t len)
{
- int wlen;
+ size_t wlen;
gfc_char4_t *q;
wlen = f->u.string.length < 0
|| (f->format == FMT_G && f->u.string.length == 0)
- ? len : f->u.string.length;
+ ? len : (size_t) f->u.string.length;
q = (gfc_char4_t *) source;
#ifdef HAVE_CRLF
@@ -488,7 +489,7 @@ write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, int len
if (is_stream_io (dtp))
{
const gfc_char4_t crlf[] = {0x000d,0x000a};
- int i, bytes;
+ size_t bytes;
gfc_char4_t *qq;
bytes = 0;
@@ -504,7 +505,7 @@ write_a_char4 (st_parameter_dt *dtp, const fnode *f, const char *source, int len
/* Scan the source string looking for '\n' and convert it if found. */
qq = (gfc_char4_t *) source;
- for (i = 0; i < wlen; i++)
+ for (size_t i = 0; i < wlen; i++)
{
if (qq[i] == '\n')
{