From murdoch at stats.uwo.ca  Tue Nov 30 03:44:32 2004
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue Nov 30 03:44:06 2004
Subject: [Rd] data is getting corrupted
In-Reply-To: <1131.128.193.136.240.1101749262.squirrel@www.forestinformatics.com>
References: <1131.128.193.136.240.1101749262.squirrel@www.forestinformatics.com>
Message-ID: <38nnq0lmi3v96aqov831lln4mkn3bt11ud@4ax.com>

On Mon, 29 Nov 2004 09:27:42 -0800 (PST), "Jeff D. Hamann"
<jeff.hamann@forestinformatics.com> wrote:

>/* this function converts the sample list	*/
>/* from R into the internal structure		*/
>struct SAMPLE_RECORD *build_sample_from_sexp( SEXP sample )
>{

[ declarations deleted ]

>
>   char                    temp_sp_code[16];
>   struct SAMPLE_RECORD *s_ptr;
>   struct SPECIES_RECORD *sp_ptr;
>
>   s_ptr = (struct SAMPLE_RECORD *)calloc( 1, sizeof( struct SAMPLE_RECORD
>) );

This allocates a structure, initialized to all zeros.

>/*    s_ptr = (struct SAMPLE_RECORD *)Calloc( 1,  struct SAMPLE_RECORD ); */
>
>   /* *fill in the header info */
>   strcpy( s_ptr->forest,
>CHAR(STRING_ELT(get_list_element(sample,"forest"), 0)) ) ;

This copies the string element to the address s_ptr->forest points to,
which is address 0, since you didn't change it from the initial NULL.
I'm surprised you didn't get a bigger error than the one you saw.

[ more deletions ]

>I'm sure there's something I don't understand about the PROTECT/UNPROTECT
>sequence as this seems to work on smaller data.frames

Maybe you were just lucky that the overwriting at address 0 didn't
trash anything in those cases?

Duncan Murdoch


[Rd] data is getting corrupted
Duncan Murdoch