Becareful when declaring large XML variables in COBOL for AIX
BasilTK 060001VVJ7 Visits (3514)
Consider the COBOL snippet below:
The above code in its entirety will compile correctly. However, when running the resulting exe, you may experience a segfault issue at runtime as shown below:
However, if you comment out IF ( XML-TEXT = 0 ), it runs fine without a segfault. Why so?
This is because we actually run out of memory on the stack due following line:
Notice that we reserve about 40 million bytes of memory on the stack for the following line:
The IF statement below is comparing an alphanumeric to a numeric:
IF ( XML-TEXT = 0 )
The numeric 0 gets turned into 1 byte zoned variable. It then compares the fiirst character of XML-TEXT to the one byte zoned number.
It's at this stage where we run into the problem. To compare the rest of XML-TEXT to blanks, we first determine how big it could be; and right now in the example we try to create a character temp equivalent in size to XML-TEXT which is "PIC X(40000000)" in size, memset it to blanks and compare to XML-TEXT. The character temp is in automatic storage (stack based). It is at this point where we try to create the temp and we end up failing due to the lack of available memory.
Hope this helps!