re PR libfortran/15204 (ADJUSTR intrinsic accesses corrupted pointer)
authorBud Davis <bdavis9659@comcast.net>
Thu, 13 May 2004 10:11:02 +0000 (10:11 +0000)
committerBud Davis <bdavis@gcc.gnu.org>
Thu, 13 May 2004 10:11:02 +0000 (10:11 +0000)
        PR fortran/15294
        * gfortran.fortran-torture/execute/adjustr.f90: New file.
        * io/intrinsic/string_intrinsics.c(adjustr): rework logic.

From-SVN: r81771

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.fortran-torture/execute/adjustr.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/intrinsics/string_intrinsics.c

index 7f62d4b07db7685be8c1ffb008e0632da8ad7d07..be4920e880cdadeebc28ef71d0a38fea8d251538 100644 (file)
@@ -1,3 +1,8 @@
+2004-05-13  Bud Davis  <bdavis9659@comcast.net>
+
+       PR fortran/15294
+       * gfortran.fortran-torture/execute/adjustr.f90: New file.
+
 2004-05-13  Diego Novillo  <dnovillo@redhat.com>
 
        Merge from tree-ssa-20020619-branch.  See
diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/adjustr.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/adjustr.f90
new file mode 100644 (file)
index 0000000..8264ba7
--- /dev/null
@@ -0,0 +1,46 @@
+! pr 15294 - [gfortran] ADJUSTR intrinsic accesses corrupted pointer
+!
+  program test_adjustr
+  implicit none
+  integer test_cases
+  parameter (test_cases=13)
+  integer i
+  character(len=10) s1(test_cases), s2(test_cases)
+  s1(1)='A'
+  s2(1)='         A'
+  s1(2)='AB'
+  s2(2)='        AB'
+  s1(3)='ABC'
+  s2(3)='       ABC'
+  s1(4)='ABCD'
+  s2(4)='      ABCD'
+  s1(5)='ABCDE'
+  s2(5)='     ABCDE'
+  s1(6)='ABCDEF'
+  s2(6)='    ABCDEF'
+  s1(7)='ABCDEFG'
+  s2(7)='   ABCDEFG'
+  s1(8)='ABCDEFGH'
+  s2(8)='  ABCDEFGH'
+  s1(9)='ABCDEFGHI'
+  s2(9)=' ABCDEFGHI'
+  s1(10)='ABCDEFGHIJ'
+  s2(10)='ABCDEFGHIJ'
+  s1(11)=''
+  s2(11)=''
+  s1(12)=' '
+  s2(12)=' '
+  s1(13)='          '
+  s2(13)='          '
+  do I = 1,test_cases
+     print*,i
+     print*, 's1          = "', s1(i), '"'
+     print*, 's2          = "', s2(i), '"'
+     print*, 'adjustr(s1) = "', adjustr(s1(i)), '"'
+     if (adjustr(s1(i)).ne.s2(i)) then
+         print*,'fail'
+         call abort
+     endif
+  enddo
+   
+  end program test_adjustr
index 1f4dd23e1d33749b2c622375187a5c3ba3f45df3..b597f52baa4843164d95db8f3bb80d0574dcd18e 100644 (file)
@@ -1,3 +1,8 @@
+2004-05-13  Bud Davis  <bdavis9659@comcast.net>
+
+       PR fortran/15294
+       * io/intrinsic/string_intrinsics.c(adjustr): rework logic.
+
 2004-05-06  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
            Steven Bosscher  <stevenb@suse.de>
 
index 999807ed1d0fcdd3eac50b89ebf1fbff19ea9c33..2cd07a2b77b01794a17d6a624ea8f1ef9adc7f70 100644 (file)
@@ -276,12 +276,11 @@ adjustr (char *dest, GFC_INTEGER_4 len, const char *src)
 
   i = len;
   while (i > 0 && src[i - 1] == ' ')
-    i++;
+    i--;
 
-  if (i < len)
-    memcpy (&dest[len - i], &src, i);
   if (i < len)
     memset (dest, ' ', len - i);
+  memcpy (dest + (len - i), src, i );
 }