Unanswered: Linux: 4GL calling C function - memory fault
I am using IDS 11.50.FC7IE on RHEL 2.6.18.
I have a 4GL function and it calls the C function by
where x,y & z are the parameters.
But it is giving memory fault (coredump).
If I don't pass the parameters, then the program is working fine. Even in HP unix the program is working fine even with argument passing. Only in RHEL I am facing this issue.
The C function uses popvchar, popint and popquote to get the arguments passed to it. But when I am passing arguments, the program is failing even before call to these functions. So these functions should not be the root cause of the problem. The problem must be lying with argument passing mechanism.
Can you please let me know what can be the root cause of the problem and how to solve it?
Actually problem was lying in the popvchar function call. The 4GL funtion calls the C function and passes "str" and "len" as arguments. The C function function then calls popvchar(str,len); this will be used to extract the "str" string of "len" legth from the stack.
But here the the "len" variable is not passed correctly as an argument to the popvchar function.
Both popquote( ) and popvchar( ) copy exactly len bytes into the string buffer *qv. Here popquote( ) pads with spaces as necessary, but popvchar( ) does not pad to the full length. The final byte copied to the buffer is a null byte to terminate the string, so the maximum string data length is len-1. If the stacked argument is longer than len-1, its trailing bytes are lost and it can't retrieve the argument from the stack and memory fault occurs.
So we have to call the popvchar() by popvchar(str,len-1).
Hope this will help the others facing the similar problem.
The exemple you´ve you shown and the link for IBM help page is how to call a C function with EGL programing and not with 4GL.
The 4GL reference PDF manual on http://publib.boulder.ibm.com/epubs/pdf/8776.pdf on Appendix C calling "Using C with INFORMX-4GL" it is the similar explication:
extern void popvchar(int1 *qv, mint len)
where as you said you can catch the information and yes... the mint len as to be the all bytes of the string minus one.
However it seams your file is not in binary or is it?
If not, you could all made with 4GL is no need to use C functions.