Re: [Rd] data is getting corrupted

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue 30 Nov 2004 - 13:44:32 EST

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



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Nov 30 13:49:12 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:01:54 EST