]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix uninitialized read in testcase gfortran.dg/pdt_48.f03
authorHarald Anlauf <anlauf@gmx.de>
Fri, 26 Sep 2025 17:20:39 +0000 (19:20 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 26 Sep 2025 17:20:39 +0000 (19:20 +0200)
Running the testcase using valgrind --leak-check=full --track-origins=yes:

==28585== Conditional jump or move depends on uninitialised value(s)
==28585==    at 0x400E19: MAIN__ (pdt_48.f03:48)
==28585==    by 0x400EDB: main (pdt_48.f03:34)
==28585==  Uninitialised value was created by a heap allocation
==28585==    at 0x4841984: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28585==    by 0x400975: __pdt_m_MOD_add (pdt_48.f03:30)
==28585==    by 0x400D84: MAIN__ (pdt_48.f03:44)
==28585==    by 0x400EDB: main (pdt_48.f03:34)

The cause was a partial initialization of a vector used in a subsequent
addition.  Initialize the remaining elements of the first vector by zero.

gcc/testsuite/ChangeLog:

* gfortran.dg/pdt_48.f03:

gcc/testsuite/gfortran.dg/pdt_48.f03

index ed60b91c8c906a20222d5d95fe68e3cfad61cff8..41b4b045cc153c7fd997187395b9db4998787d0b 100644 (file)
@@ -16,17 +16,18 @@ contains
     integer :: c
     c=max(a,b)
   end function diy_max
-                
+
   function add(a,b) result(c)
     type(vec(k=*)), intent(in) :: a,b
     type(vec(k=max(a%k,b%k))) :: c      ! Fails
     !type(vec(k=diy_max(a%k,b%k))) :: c ! Worked with diy_max
     !type(vec(k=a%k+b%k)) :: c          ! Worked with +
-    
+
     c%foo(1:a%k)=a%foo
+    c%foo(a%k+1:) = 0
     c%foo(1:b%k)=c%foo(1:b%k)+b%foo
 
-    if (c%k /= 5) stop 1 
+    if (c%k /= 5) stop 1
   end function add
 end module pdt_m