[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
970511: bug in netcdf 3.3beta NCAINQ()
- Subject: 970511: bug in netcdf 3.3beta NCAINQ()
- Date: Mon, 12 May 97 09:26:15 -0600
Kate,
> To: address@hidden
> cc: address@hidden
> From: Kate Hedstrom <address@hidden>
> Subject: bug in netcdf 3.3beta
> Organization: Rutgers University
> Keywords: 199705110252.UAA11265
In the above message, you wrote:
> I have installed version 3.3beta on systems running Solaris 2, SunOS 4,
> and IRIX 6.2. We found a problem that only shows up under Solaris 2
> (where it leads to a seg violation and core dump). However, I have
> tracked it down and found that it is a universal problem and some
> systems are just more forgiving about it.
>
> I have a file which contains a global attribute of 'type', so we
> inquire about it with:
>
> call ncainq (ncid,NCGLOBAL,'type',attype,ltype,rcode)
>
> It was dumping core in memcpy which didn't make sense to me until I got
> the gcc version of cpp to expand:
>
> FCALLSCSUB6(c_ncainq,NCAINQ,ncainq,INT,INT,PSTRING,PINT,PINT,PINT)
>
> to (plus or minus some whitespace):
>
> void ncainq_ (int* A1, int* A2, char* A3,
> int* A4, int* A5, int* A6, unsigned C3 ) {
> char * B3 = ((void *)0) ; ;
> c_ncainq (* A1, * A2,
> (( B3 =malloc(C3 + 1))[C3]='\0', memcpy(B3, A3, C3),
> kill_trailing(B3 ,' ')), A4, A5, A6);
> if (B3) memcpy(A3, B3,(( strlen(B3) )<(C3)?( strlen(B3)):(C3)) ),
> (C3 >strlen(B3)? memset(A3 +strlen(B3),' ', C3-strlen(B3)):0)
> , free(B3);
> return ;
> }
>
> This function declares a C type string B3 and copies the value of A3
> into it, in this case 'type'. It knows the length because that is
> passed in the C3 argument. It can then call the C routine c_ncainq.
> Where it fails is on the clean-up. For some incomprehensible reason it
> tries to copy B3 back into A3. Since A3 is 'const' in this case we get
> into trouble and it dumps core. Your test program succeeds when
> testing ncainq because your test uses a variable rather than a string
> literal for the name of the attribute.
Great bug! Thanks!
>
> I could fix this in the code after cpp has done its thing, but I
> couldn't possibly fix this correctly.
The correct solution is to change the definition of NCAINQ from
FCALLSCSUB6(c_ncainq,NCAINQ,ncainq,INT,INT,PSTRING,PINT,PINT,PINT)
to
FCALLSCSUB6(c_ncainq,NCAINQ,ncainq,INT,INT,STRING,PINT,PINT,PINT)
i.e. change "PSTRING" to "STRING". You should also add a "const"
qualified to the declaration of attname in the previous c_ncainq()
function -- just to keep things honest.
This will be fixed in the next release. Thanks for the feedback.
--------
Steve Emmerson <address@hidden>