[Info-vax] calloc fails with access violation

jls notvalid at yahoo.com
Wed Aug 26 16:38:21 EDT 2009


On Wed, 26 Aug 2009 10:03:14 -0700 (PDT), Jose Cuevas
<jcuevas at mac.com> wrote:
>
>PS I'll not be happy until I understand how the char * VS descriptor
>thing is messing with my calloc. The things that do not add-up yet
>are: i'm copying the contents of the cobol string to a c-string, I
>inspect the contents of the strings and all seems to be in order, from
>then on all I use is the string created in C. The address of the
>descriptor is the same as that of the char *, the only difference I
>see is that descriptor gives me a size, which is not an issue in my
>case. The ACCESSVIOL is raised at different places and never with the
>same record. (does tend to repeat somewhat with the same record but
>not in a consistent way). We have another C library that we use in
>Cobol with char * and never had problems with it for about 4 years
>now.
>
>I appreciate every ones help, will keep trying all of your suggestions.

This sounds suspiciously like a FORTRAN problem I ran into in my
programming days.  I would get strange ACCVIO errors and other data
issues.  Running in the debugger, I found a variable being modified
when it wasn't being used.

It took awhile for me to figure out that a string variable was being
stuffed with a string much longer than the variable allocated, which
meant that the program was just filling in whatever memory addresses
came after the variable.  

Sometimes that memory address would be writable - i.e., modify the
contents of another variable.  Other times it would be a code page and
I'd (thankfully) get an ACCVIO.

One way to fix this was to compile with "/check=bounds" (IIRC), which
would raise a more meaningful whenever a user would enter more data
than would fit in my variable.  When the overflow occurred, the stack
dump would tell me exactly which variable and which line of code.

Of course, I eventually learned better ways to protect myself and
prevent buffer overruns.




More information about the Info-vax mailing list