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,768 of 264,096    |
|    =?UTF-8?Q?Arne_Vajh=C3=B8j?= to Dan Cross    |
|    Re: VMS Bootcamp    |
|    15 Nov 25 19:00:04    |
      From: arne@vajhoej.dk              On 11/15/2025 10:04 AM, Dan Cross wrote:       > In article <10f30sp$1koun$4@dont-email.me>,       >> I consider the 3 biggest memory unsafe problems to be:       >> * no out of bounds check for array index       >> * allowing use of deallocated memory       >> * memory leak due to memory never being deallocated              >> Pascal only prevents the first not the other two.       >>       >> The other two are not as common in Pascal as in C,       >> because dynamic memory allocation is not as common in       >> Pascal as in C.       >       > Pascal is certainly an improvement over (at least) C and       > assembler languages in this domain: as I recall, it doesn't       > support arbitrary pointer arithmetic,              Standard: no.              VMS: only if jumping through hoops.              Delphi: easy peasy.              VMS code:              program pasptr(input,output);              type        char_arr = packed array [1..3] of char;        char_arr_ptr = ^char_arr;              var        p : char_arr_ptr;        hack1, hack3 : char_arr_ptr;        hack2, hack4 : [unsafe] char_arr_ptr;              begin        new(p);        p^ := 'ABC';        writeln(p^[1]);        hack1 := (p::integer + 1)::char_arr_ptr;        writeln(hack1^[1]);        hack2 := p::integer + 2;        writeln(hack2^[1]);        hack3 := (iaddress(p^) + 1)::char_arr_ptr;        writeln(hack3^[1]);        hack4 := iaddress(p^) + 2;        writeln(hack4^[1]);        dispose(p);       end.              That code is screaming for a code review.              Delphi code:              program pasptr(input, output);              var        p : pchar;        hack1, hack2 : pchar;              begin        GetMem(p, 3);        p := 'ABC';        writeln(p[0]);        hack1 := p + 1;        writeln(hack1[0]);        hack2 := @p[0] + 2;        writeln(hack2[0]);       end.              That code is C in Pascal.              > and arrays are properly       > typed by including the array size in the type, and so on.       Either the dimension(s) is in the compile time declaration or       passed at runtime.              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