Troubleshooting
Problem
This document shows how an ILE RPG program calling a C/C++ program that uses strcpy() could cause a message MCH0601.
Resolving The Problem
This document shows how an RPG program calling a C/C++ program that uses strcpy() could cause an MCH0601.
Problem
The issue manifests as an MCH0601 to and from the end user program.
MCH0601 Escape 40 02/28/12 11:53:02.720264 PGMNAME PGMLIB *STMT PGMNAME PGMLIB *STMT
From module . . . . . . . . : PARSER
From procedure . . . . . . : strcpy__FPcPCc
Statement . . . . . . . . . : 1
To module . . . . . . . . . : PARSER
To procedure . . . . . . . : strcpy__FPcPCc
Statement . . . . . . . . . : 1
Message . . . . : Space offset X'00058000' or X'0000000000000000' is outside
current limit for object JOBNAME JOBUSER JOBNUM.
The procedure name shows that they're trying to do a strcpy().
The calling RPG program used the following prototype:
D Fcn1 pr 5i 0 extproc('eval__FPcRr')
D 65535a
D 8f
Variable definitions:
D Rtn s 5i 0 inz(0)
D Str S 65535A
D Flt s 8f
And the call:
C Eval Rtn = Fcn1(Str:Flt)
The C/C++ function had the following definition:
short int eval(char *string, long double &result)
The call to strcpy() was embedded several functions deep in the C/C++ code.
Resolution
strcpy() was signalling a message MCH0601 because it tried to address space beyond the end of the string that it was working with. As documented in the ILE C/C++ Runtime Library Functions manual, strcpy() does not perform any sort of length checking on the string that it is working with; it depends on the string being null terminated.
The solution was to change the RPG prototype to ensure that the string being passed to the C/C++ program was null terminated. This can be done by using the OPTIONS(*STRING) keyword on a pointer data type, as shown below:
D Fcn1 pr 5i 0 extproc('eval__FPcRr')
D * Value Options(*String)
D 8f
Problem
The issue manifests as an MCH0601 to and from the end user program.
MCH0601 Escape 40 02/28/12 11:53:02.720264 PGMNAME PGMLIB *STMT PGMNAME PGMLIB *STMT
From module . . . . . . . . : PARSER
From procedure . . . . . . : strcpy__FPcPCc
Statement . . . . . . . . . : 1
To module . . . . . . . . . : PARSER
To procedure . . . . . . . : strcpy__FPcPCc
Statement . . . . . . . . . : 1
Message . . . . : Space offset X'00058000' or X'0000000000000000' is outside
current limit for object JOBNAME JOBUSER JOBNUM.
The procedure name shows that they're trying to do a strcpy().
The calling RPG program used the following prototype:
D Fcn1 pr 5i 0 extproc('eval__FPcRr')
D 65535a
D 8f
Variable definitions:
D Rtn s 5i 0 inz(0)
D Str S 65535A
D Flt s 8f
And the call:
C Eval Rtn = Fcn1(Str:Flt)
The C/C++ function had the following definition:
short int eval(char *string, long double &result)
The call to strcpy() was embedded several functions deep in the C/C++ code.
Resolution
strcpy() was signalling a message MCH0601 because it tried to address space beyond the end of the string that it was working with. As documented in the ILE C/C++ Runtime Library Functions manual, strcpy() does not perform any sort of length checking on the string that it is working with; it depends on the string being null terminated.
The solution was to change the RPG prototype to ensure that the string being passed to the C/C++ program was null terminated. This can be done by using the OPTIONS(*STRING) keyword on a pointer data type, as shown below:
D Fcn1 pr 5i 0 extproc('eval__FPcRr')
D * Value Options(*String)
D 8f
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"and future releases;7.1.0"}]
Historical Number
626587678
Was this topic helpful?
Document Information
Modified date:
08 May 2025
UID
nas8N1011104