[Info-vax] calloc fails with access violation

Jose Cuevas jcuevas at mac.com
Mon Aug 24 14:28:34 EDT 2009


On Aug 24, 1:45 pm, VAXman-  @SendSpamHere.ORG wrote:
> In article <aecec9c9-3fe0-4b76-b37a-c5cd9ebf5... at a13g2000yqc.googlegroups.com>, Jose Cuevas <jcue... at mac.com> writes:
>
>
>
>
>
> >1. We have a problem with a fairly simple library written in C that
> >gets called from Cobol.
>
> >The C library is used to PUSH data generated by the Cobol application
> >over HTTP POST using sockets.
>
> >We are getting an access violation (a crash) on calls to calloc() of
> >insignificant size. While at first we thought it was on a particular
> >record we then found that it is a far more inconsistent.
>
> >The C code runs fine when tested on a unix machine.
>
> >2. Unrelated question: if we send a variable from a record structure
> >to a C function we get an access violation. So far the only workaround
> >we found is to move variables to one defined at the working-storage.
> >Any ideas on how to use record variables as parameters for C
> >functions?
>
> Don't post a snippet of the code which you are questioning -- hint,
> hint.  
>
> If you are calling C routines from Cobol, make certain that you are
> passing the data properly.  Strings, for example, in COBOL are typ-
> ically passed by DESCRIPTOR whereas C will pass references to null-
> terminated byte streams.  I would expect any C code to get rather
> upset if passed a string DESCRIPTOR in lieu of a reference to null-
> terminated streams.
>
> --
> VAXman- A Bored Certified VMS Kernel Mode Hacker    VAXman(at)TMESIS(dot)ORG
>
>  http://www.quirkfactory.com/popart/asskey/eqn2.png
>
>   "Well my son, life is like a beanstalk, isn't it?"

1. The code fails randomly at different points that use calloc. For
example at the C function.

char *ckGetCobolString(char *sIn){
	int i = 0;
	char *s = calloc(strlen(sIn), sizeof(char));
	strcpy(s, sIn);
	for(i=strlen(sIn)-1;i>=0; i--){
		/*skip whites*/
		if(s[i] != ' ') break;
	}
	s[i+1] = '\0';
	return s;
}

In the above code I can printf the pointer sIn and do a strlen without
problems, it is not the strlen crashing. If we use static strings
(char arrays) in C the code works. But thats not an option as the size
of data is unknown.

In Cobol we use:
  DATA DIVISION.
  FILE SECTION.
    05  E0-NOMBRE-COMPLETO.
        10  E0-PATERNO			PICTURE  X(15).
        10  E0-MATERNO			PICTURE  X(15).
        10  E0-NOMBRE			PICTURE  X(14).
        10  E0-INICIAL			PICTURE  X(01).
    ....
 WORKING-STORAGE SECTION.
    01      WS-NOMBRE-COMPLETO                      PICTURE  X(45).
    ....
 PROCEDURE DIVISION.
    CALL "ckDefineField" USING "name".
    ....
    MOVE E0-NOMBRE-COMPLETO TO WS-NOMBRE-COMPLETO.
    CALL "ckSetField" USING "name", WS-NOMBRE-COMPLETO.


2. As far as calling C code from Cobol we only found one example in HP
website, any help or information on the proper way to pass values will
be greatly appreciated. We have a CGI library that we call from Cobol
written in house and have no problems.

3. We are running OpenVMS V7.2-2.



More information about the Info-vax mailing list