OpenCOBOL Forum Index OpenCOBOL
Issue between declared variables in linkage section in callee sub and "real" variables in caller sub | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| 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 SUB PRG2 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 is 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 |
| btiffin | Posted on: 2012/2/27 21:25 |
Home away from home ![]() ![]() Joined: 2008/6/7 From: CANADA Posts: 1196 |
Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub I don't think the memcpy is the problem.
Looks more like an error with STR-PRG1 naming on the prg2.cob PROCEDURE DIVISION. OpenCOBOL is pretty nice about messages with -W, -g and -debug. Try and then It won't abend, but the last 14000 chars in PRG2 STR-PRG2 is going to be a load of junk. Cheers, Brian |
| 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 : PRG3 : PRG2 : 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 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 ? |
| human | Posted on: 2012/2/28 11:45 |
Home away from home ![]() ![]() Joined: 2007/5/15 From: GERMANY Posts: 1416 |
Re: Issue between declared variables in linkage section in callee sub and "real" variables in caller sub As btiffin said: This is a coding error, not a runtime issue. Therefore I believe there will be no change to cob_module/cob_move as it SHOULD crash here (Think of important stuff you pass on CALL and expect to be used).
What I hope is that the size of the using/linkage items will be checked in the future (at least with -debug) and the runtime exits with an error as a segfault is not easy to find. human |
| eraso | Posted on: 2012/2/28 13:55 |
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,
Thank you for your time Btiffin and Human. Human, the suggestion you made is The solution. By now I rewrite manually the parts wrongly coded. KR, eraso |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |







