home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 263,746 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: VMS Bootcamp   
   12 Nov 25 17:21:48   
   
   From: arne@vajhoej.dk   
      
   On 11/12/2025 5:14 PM, Arne Vajhøj wrote:   
   > I do not see a problem with the pointer type casts. If   
   > normal code is safe, then I think it is OK to have ways   
   > to workaround the safeness. Sometimes it is desirable   
   > and it is hopefully easy to identify usage of such   
   > constructs and require extra code review of such code.   
      
   Illustration:   
      
   $ type m1.pas   
   program m1(input,output);   
      
   type   
       a4 = array [1..4] of integer;   
       pa4 = ^a4;   
      
   var   
       ap : pa4;   
       i : integer;   
      
   begin   
       new(ap);   
       for i := 1 to 5 do begin   
          ap^[i] := i;   
          writeln(i);   
       end;   
       dispose(ap);   
   end.   
   $ pas m1   
   $ link m1   
   $ run m1   
             1   
             2   
             3   
             4   
   %PAS-F-ARRINDVAL, array index value is out of range   
   %TRACE-F-TRACEBACK, symbolic stack dump follows   
   image     module    routine               line      rel PC           abs PC   
   m1  M1  M1                                  14 00000000000000DC   
   00000000800000DC   
                                                 0 FFFF8300071C81C6   
   FFFF8300071C81C6   
   DCL                                          0 000000008006632B   
   000000007ADC432B   
   %TRACE-I-END, end of TRACE stack dump   
   $ type m2.pas   
   program m2(input,output);   
      
   type   
       a4 = array [1..4] of integer;   
       pa4 = ^a4;   
       a5 = array [1..5] of integer;   
       pa5 = ^a5;   
      
   var   
       ap : pa4;   
       hack : pa5;   
       i : integer;   
      
   begin   
       new(ap);   
       hack := ap::pa5;   
       for i := 1 to 5 do begin   
          hack^[i] := i;   
          writeln(i);   
       end;   
       dispose(ap);   
   end.   
   $ pas m2   
   $ link m2   
   $ run m2   
             1   
             2   
             3   
             4   
             5   
   $ type m3.pas   
   program m3(input,output);   
      
   type   
       a4 = array [1..4] of integer;   
       pa4 = ^a4;   
       a5 = array [1..5] of integer;   
       pa5 = ^a5;   
       pa4_or_pa5 = record   
                       case boolean of   
                          false: (f4 : pa4);   
                          true: (f5 : pa5);   
                    end;   
      
   var   
       ap : pa4;   
       hack : pa4_or_pa5;   
       i : integer;   
      
   begin   
       new(ap);   
       hack.f4 := ap;   
       for i := 1 to 5 do begin   
          hack.f5^[i] := i;   
          writeln(i);   
       end;   
       dispose(ap);   
   end.   
   $ pas m3   
   $ link m3   
   $ run m3   
             1   
             2   
             3   
             4   
             5   
      
   Pointer type cast and variant records just scream for   
   a critical code review.   
      
   And other languages also allow circumventing checks.   
      
   Including C#!   
      
   using System;   
      
   namespace AA   
   {   
        public class Program   
        {   
            public static void Main(string[] args)   
            {   
                int[] a = new int[4];   
                for(int i = 0; i < 5; i++)   
                {   
                    a[i] = i;   
                    Console.WriteLine(i);   
                }   
            }   
        }   
   }   
      
   0   
   1   
   2   
   3   
      
   Unhandled Exception: System.IndexOutOfRangeException: Index was outside   
   the bounds of the array.   
       at AA.Program.Main(String[] args) in   
   c:IDEProjects\SharpDevelop5\aa\aa\Program.cs:line 12   
      
   using System;   
      
   namespace AAX   
   {   
        public class Program   
        {   
            public static void Main(string[] args)   
            {   
                int[] a = new int[4];   
                unsafe   
                {   
                    fixed (int* hack = &a[0])   
                    {   
                        for(int i = 0; i < 5; i++)   
                        {   
                            hack[i] = i;   
                            Console.WriteLine(i);   
                        }   
                    }   
                }   
            }   
        }   
   }   
      
   0   
   1   
   2   
   3   
   4   
      
   unsafe { } clearly reveal that something fishy is going on.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca