Bug 31297 - Use of uninitialized variables in libgfortran's I/O
Summary: Use of uninitialized variables in libgfortran's I/O
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Thomas Koenig
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2007-03-21 14:18 UTC by Tobias Burnus
Modified: 2007-05-18 20:52 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.3 4.2.0 4.3.0
Last reconfirmed: 2007-03-25 10:47:44


Attachments
patch for the test cases (968 bytes, patch)
2007-03-24 22:44 UTC, Thomas Koenig
Details | Diff
proposed patch (1.36 KB, patch)
2007-03-24 23:07 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-03-21 14:18:53 UTC
Found using valgrind:

gfortran gfortran.dg/backspace_5.f
valgrind ./a.out

==15340== Syscall param write(buf) points to uninitialised byte(s)
==15340==    at 0x56000C0: __write_nocancel (in /lib64/libc-2.5.so)
==15340==    by 0x4EBEE90: do_write (unix.c:336)
==15340==    by 0x4EBEF31: fd_flush (unix.c:386)
==15340==    by 0x4EBCBF6: _gfortran_st_write_done (transfer.c:2762)
==15340==    by 0x400BAB: MAIN__ (in /projects/tob/gcc/gcc/testsuite/gfortran.dg/a.out)
==15340==    by 0x40104B: main (fmain.c:22)

Similarly for:
- backspace_6.f
- write_back.f
- write_rewind_1.f
- write_rewind_2.f
- char_bounds_check_fail_1.f90
- direct_io_2.f90
- unf_io_convert_3.f90
Comment 1 Thomas Koenig 2007-03-24 22:17:27 UTC
This is a bug in the test case.

I'll commit a correct version.

Thomas
Comment 2 Thomas Koenig 2007-03-24 22:44:32 UTC
Created attachment 13279 [details]
patch for the test cases

All but one of these were errors in the test cases, which are
corrected with this patch.

unf_io_convert_3.f90 is a case where we don't initialize the left-over
bytes when converting.  Hmm... I'll have to look into this some
more.
Comment 3 Thomas Koenig 2007-03-24 23:07:37 UTC
Created attachment 13280 [details]
proposed patch

This one also fixes the last case.

It does so by reading size bytes instead of the kind number when
converting endianness.  This makes the buffers initialized, and
also makes sure the number of bytes are the same when
using CONVERT="SWAP" or when using the native format.

Not that I really expect anybody to use CONVERT with 10-byte
reals, anyway :-)
Comment 4 Thomas Koenig 2007-03-25 21:18:01 UTC
Subject: Bug 31297

Author: tkoenig
Date: Sun Mar 25 21:17:51 2007
New Revision: 123200

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123200
Log:
2007-03-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/31297
	* gfortran.dg/backspace_5.f:  Initialize variable(s).
	* gfortran.dg/backspace_6.f:  Likewise.
	* gfortran.dg/char_bounds_check_fail_1: Likewise.
	* gfortran.dg/direct_io_2.f90:  Likewise.
	* gfortran.dg/write_back.f:  Likewise.
	* gfortran.dg/write_rewind_2.f:  Likewise.
	* gfortran.dg/write_rewind_1.f:  Likewise.
	* gfortran.dg/write_rewind_2.f:  Likewise.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/backspace_5.f
    trunk/gcc/testsuite/gfortran.dg/backspace_6.f
    trunk/gcc/testsuite/gfortran.dg/char_bounds_check_fail_1.f90
    trunk/gcc/testsuite/gfortran.dg/direct_io_2.f90
    trunk/gcc/testsuite/gfortran.dg/write_back.f
    trunk/gcc/testsuite/gfortran.dg/write_rewind_1.f
    trunk/gcc/testsuite/gfortran.dg/write_rewind_2.f

Comment 5 Jerry DeLisle 2007-03-28 02:28:21 UTC
I think this can be closed.  No need to backport.  RE-open if anyone disagrees.
Comment 6 Thomas Koenig 2007-03-28 20:47:21 UTC
Hi Jerry,

there is still the issue with kind=10 reals written with
CONVERT="swap".

Reopening until we've decided what to do with that :-)

Thomas
Comment 7 Janne Blomqvist 2007-05-18 20:52:43 UTC
Seems unf_io_convert_3.f90 is fixed by the patch for PR31915, which adds padding for CONVERT. The patch was committed as r124741. Closing, please verify and reopen if I'm wrong.