[Info-vax] calloc fails with access violation

Bob Koehler koehler at eisner.nospam.encompasserve.org
Wed Aug 26 14:53:10 EDT 2009


In article <f833442d-3560-4317-b17c-7535eaf2b4d6 at l5g2000yqo.googlegroups.com>, Jose Cuevas <jcuevas at mac.com> writes:
> 
> That using char * as arguments in C when using "BY REFERENCE" in cobol
> does not make a difference at all.

   "BY REFERENCE" tells COBOL to pass the address of the data, not the
   descriptor it would usually use for strings (I didn't see that in the
   COBOL snipet you posted).  There's a very good chance that the data 
   would accidentally be followed by a null, but no guarrantee.

   Unless you create a null terminated string, you can get away with
   things like strncpy, which accept a length argument, provided you
   know what the length is.

   Before you call any C RTL routine from a program who's main (entry
   point) is not written in C, you may need to call DECC$CTRL_INIT.
   I don't think that is required for calloc(), but it is for I/O.

> All strings returned the same size,
> and I was able to treat them a null-strings in the C side. That makes
> think that the runtime is doing the conversion for me.  I tested every
> standard library in C that I know depends on NULL and they work, I
> loop tru the pointer and it has a NULL.

   I suspect very strongly that the null you are seeing is accidental.
   Try a string who's length is a multiple of 16.

> 
> I started re-factoring the code one piece at a time and testing each
> element by it self. I found that my code is crashing at a point I have
> a string that I just malloced, I can printed, I can get its size. This
> is a c-string not a cobol string. Then when I pass this same char * as
> argument to another c function. In the other function I can print it,
> I can get it size. As soon as I try to alloc it craches with an access
> violation in:
> 
> char *encoded=calloc(sz*2,sizeof(char)); int i=0;
> 
> I'll play with it more, and I will try the other suggestions also.



More information about the Info-vax mailing list