HOME  NEWS  FORUM  DOWNLOAD  LINK
OpenCOBOL - an open-source COBOL compiler
Main Menu
Download
Documentation
Development
Who's Online
11 user(s) are online (3 user(s) are browsing Forum)

Members: 0
Guests: 11

more...
Powered by
SourceForge

Xoops

Creative Commons

OpenCOBOL Forum Index
   OpenCOBOL
     Issue between declared variables in linkage section in callee sub and "real" variables in caller sub
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
eraso
Posted on: 2012/2/27 17:06
Not too shy to talk
Joined: 2006/11/22
From: SUTEC - Fontenay sous Bois (France)
Posts: 21
Issue between declared variables in linkage section in callee sub and "real" variables in caller sub
Hello,

I have encountered the code below in the application I'm migrating :

PROGRAM PRG1
       *
        IDENTIFICATION DIVISION.
        PROGRAM-ID. PRG1.

        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 STR-PRG1.
           10  BUFFER PIC X(2000).

        PROCEDURE DIVISION.
        INITIALIZE STR-PRG1.
        CALL "PRG2" USING STR-PRG1.
        EXIT PROGRAM.

SUB PRG2
       *
        IDENTIFICATION DIVISION.
        PROGRAM-ID. PRG2.

        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 STR-PRG2.
           10  BUFFER PIC X(16000).
        LINKAGE SECTION.
        01 STR-PRG1.
           10  BUFFER PIC X(16000).

        PROCEDURE DIVISION.
        MOVE STR-PRG1 TO STR-PRG2.
        EXIT PROGRAM.

As you can read the programs above :
- the caller sub declares a variable of 2000 bytes
- the callee sub declares the same variable of 16000 bytes through the linkage section and a working variable of the same length

The only action made is to copy the value from caller variable to callee variable :
The translation in C language for the line
  MOVE STR-PRG1 TO STR-PRG2.

is
  {
    memcpy (b_5, b_7, 16000);
  }

that is syntactically correct
but the real length of b_7 is 2000 not 16000 so an exception is risen "Attempt to reference unallocated memory (Signal SIGSEGV)" (OC 1.1) / "Memory Fault" (OC 0.33)

I understand that this issue (maybe someone has already written a post about this problem but I haven't found any) is due to the asset i'm working on but could the problem and the solution may lie between using the cob_module structure and the cob_move function, as when the move action between two variables of different lengths is done by the cob_move function ?

KR,

eraso
Flat Previous Topic | Next Topic

Subject Poster Date
 » Issue between declared variables in linkage section in callee sub and "real" variables in caller sub eraso 2012/2/27 17:06
     Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub btiffin 2012/2/27 21:25
       Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub eraso 2012/2/28 10:42
         Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub human 2012/2/28 11:45
           Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub eraso 2012/2/28 13:55

Register To Post
 
Copyright (C) 2005 The OpenCOBOL Project. All rights reserved.
Powered by Xoops2 | PHP | MySQL | Apache
ocean-net