logoalt Hacker News

erik_seaberg10/01/20241 replyview on HN

Sorry, https://www.ibm.com/docs/en/cobol-zos/6.2?topic=statement-ex... seems to be demonstrating a language that is not memory-safe (maybe it used to be, but how?)

  COMPUTE SIZE-NEEDED = LENGTH OF OBJ + LENGTH OF VARTAB * NUM-ELEMENTS
  ALLOCATE SIZE-NEEDED CHARACTERS INITIALIZED RETURNING VPTR
  SET ADDRESS OF VARGRP TO VPTR
  MOVE NUM-ELEMENTS TO OBJ
  MOVE BUFFER(1:SIZE-NEEDED) TO VARGRP
  SET VPTR TO ADDRESS OF BUFFER
  FREE VPTR

Replies

palisade10/01/2024

The compiler would have rejected that, if I remember correctly. I'm not in the field of cobol myself, I learned it briefly in college ages ago.

show 1 reply