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

Members: 0
Guests: 26

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/28 10:42
Not too shy to talk
Joined: 2006/11/22
From: SUTEC - Fontenay sous Bois (France)
Posts: 21
Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub
Hello,

Btiffin, thanks for your reply.

Well I made a mistake when I wrote the program samples for the problem I encountered in the asset I'm working with (I may repeat myselft but, in french, cela va sans dire mais ca va mieux en le disant).
What I wanted to point is around the definition of variables in linkage section and their use in callee sub and the real definition in caller sub.
So I wrote two executables PRG1 and PRG3 calling PRG2 as you can see below :
(I compiled PRG1 and PRG3 as executable - cobc -x -debug - and PRG2 as shared library - cobc -m -debug)

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.

PRG3 :
*
 IDENTIFICATION DIVISION.
 PROGRAM-ID. PRG3.

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

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

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 USING STR-PRG1.
 MOVE STR-PRG1 TO STR-PRG2.
 DISPLAY "MOVE DONE".
 EXIT PROGRAM.

As you can read, if everything goes right, "MOVE DONE" is displayed on console.

Everything goes right for PRG3 but for PRG1, the output is :
Quote:
PROGRAM-ID: PRG1: ENTRY PRG1
PROGRAM-ID: PRG1: MAIN SECTION
PROGRAM-ID: PRG1: MAIN PARAGRAPH
PROGRAM-ID: PRG1 Line: 11 Statement: INITIALIZE
PROGRAM-ID: PRG1 Line: 12 Statement: CALL
PROGRAM-ID: PRG2 Line: 14 Statement: MOVE
PRG2.cbl:14: Attempt to reference unallocated memory (Signal SIGSEGV)
Abnormal termination - File contents may be incorrect


This because in PRG1 STR-PRG1 is defined of 2000 bytes long but in the linkage section of PRG2, STR-PRG1 is defined of 16000 bytes long, so the move order in PRG2 translated to memcopy instruction try to copy 16000 bytes, that is more than the real length of STR-PRG1 defined in PRG1, so that's why the exception "Attempt to reference unallocated memory (Signal SIGSEGV)" is risen.

So my question is 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 ?

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