diff mbox

[6,Regession] Usage of unitialized pointer io/list_read.c (

Message ID 56C3CEEE.4050305@charter.net
State New
Headers show

Commit Message

Jerry DeLisle Feb. 17, 2016, 1:37 a.m. UTC
See patch to fix this below.

On 02/16/2016 11:38 AM, Dominique d'Humières wrote:
> With the following reduced test
> 
> program test
>   implicit none
>   integer :: i, j, k, ios
>   integer, parameter :: big = 600
>   character(kind=4,len=big) :: str1, str2
> 
>   do i=1,big, 10
>     do j = 0, 9
>       k = i + j
>       str2(k:k) = char(65+j)
>     end do
>   end do
>   open(15, status='scratch', encoding="utf-8")
>   write(15,*) "  'abcdefgh!'", " ", str2
>   rewind(15)
>   read(15,*,iostat=ios) str1, str2
>   close(15)
> end program
> 
> valgrind shows a lot of errors before and after the commit.
> 
> Dominique
> 
>> Le 16 févr. 2016 à 18:58, Jerry DeLisle <jvdelisle@charter.net> a écrit :
>>
>> Up until now we have not had a test case like this for kind=4 testing.  I did
>> try -fsanitize=address here and do see the same thing.  I will work on this some
>> more.
>>
>> Thanks,
>>
>> Jerry
> 

It was all messed up.  This patch on current trunk fixes it here.  Please test.

Comments

Jerry DeLisle Feb. 17, 2016, 5:02 p.m. UTC | #1
On 02/16/2016 05:37 PM, Jerry DeLisle wrote:
> See patch to fix this below.
> 

Committed on trunk, r233500 after regression testing, -fsanitize=address
testing, and valgrind testing.

Jerry
diff mbox

Patch

diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index fcd4b6e..bebdd8c 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -119,7 +119,10 @@  push_char4 (st_parameter_dt *dtp, int c)
   if (dtp->u.p.saved_used >= dtp->u.p.saved_length)
     {
       dtp->u.p.saved_length = 2 * dtp->u.p.saved_length;
-      p = xrealloc (p, dtp->u.p.saved_length * sizeof (gfc_char4_t));
+      dtp->u.p.saved_string =
+       xrealloc (dtp->u.p.saved_string,
+                 dtp->u.p.saved_length * sizeof (gfc_char4_t));
+      p = (gfc_char4_t *) dtp->u.p.saved_string;
     }

   p[dtp->u.p.saved_used++] = c;