4 ms·
Sorry, https://www.ibm.com/docs/en/cobol-zos/6.2?topic=statement-example-allocate-free-storage-unbounded-tables https://www.ibm.com/docs/en/cobol-zos/6.2?topic=
by erik_seaberg 2y ago
Sorry, https://www.ibm.com/docs/en/cobol-zos/6.2?topic=statement-example-allocate-free-storage-unbounded-tables 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
- palisade 2y agoThe 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.
- electroly 2y agoWhich part do you think would be rejected? This code is an example from the z/OS COBOL documentation--I'm quite sure it works.
- palisade 2y agoThe heap stuff is new I guess, we didn't have that back when I was writing programs in it. So, yea, not so safe anymore. :D I take back what I said about it being safer then. I can't go back and edit my original post, it's been too long. The compiler did normally warn for data bounds checking, so I figured it would in this case. If that's not the case anymore then I'm wrong.