#78 Using LOCAL-STORAGE data in ASSIGN causes segfault.

GC 2.0
closed
Edward Hart
None
4
2015-06-12
2014-06-11
Edward Hart
No

Take the following program:

       >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. test-prog.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT f ASSIGN f-path
        ORGANIZATION LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD  f.
01  f-line PIC X.

LOCAL-STORAGE SECTION.
01  f-path PIC X(10) VALUE "foo.txt".

PROCEDURE DIVISION.
    OPEN INPUT f *> Segfault here
    CLOSE f
    .
END PROGRAM test-prog.

This compiles cleanly, but fails with a segfault:

./test4.cob: 22: Attempt to reference unallocated memory (Signal SIGSEGV)
Abnormal termination - File contents may be incorrect

Putting f-path into the WORKING-STORAGE SECTION fixes the error.

Related

Discussion: Introducing the ASSERT statement

Discussion

  • Simon Sobisch
    Simon Sobisch
    2014-06-11

    • status: open --> accepted
    • assigned_to: Simon Sobisch
    • Priority: 1 --> 9
     
  • Simon Sobisch
    Simon Sobisch
    2014-06-11

    Thank you for all these good bug reports.

    I'll check and likely fix it within the next days. Or do you want to try a fix on your own?

     
  • Edward Hart
    Edward Hart
    2014-06-12

    Thank you for all these good bug reports.

    That's very kind of you.

    Or do you want to try a fix on your own?

    I can't, sadly. I'm still rather clueless about how everything works in the compiler.

     
  • Edward Hart
    Edward Hart
    2014-06-13

    Actually, I can provide a simple patch. The attached patch moves allocation and initialisation of LOCAL-STORAGE to before the initialisation of the rest of the program, thereby giving the file's ASSIGN pointer something to point to. It also adds a test covering this bug to the test suite. I've no idea if the patch is acceptable, but it fixes the bug and passes the test suite.

     
  • Simon Sobisch
    Simon Sobisch
    2015-06-03

    • assigned_to: Simon Sobisch --> Edward Hart
    • Group: unclassified --> GC 2.0
    • Priority: 9 --> 4
     
  • Edward Hart
    Edward Hart
    2015-06-12

    • status: accepted --> closed
     
  • Edward Hart
    Edward Hart
    2015-06-12

    Fixed in [r604].

     

    Related

    Commit: [r604]