[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Solaris problem rallocing arrays
From: |
Manuel Guesdon |
Subject: |
Re: Solaris problem rallocing arrays |
Date: |
Tue, 20 Mar 2001 19:13:33 +0100 (CET) |
On Tue, 20 Mar 2001 10:13:46 -0700 Adam Fedor <Adam Fedor <fedor@doc.com>>
wrote:
>| I'm getting the oddest behaviour on Solaris (2.6) machines in
>| NSProcessInfo(_gnu_process_args). The code is essentially
>|
>| NSMutableArray *keys = [NSMutableArray new];
>|
>| for {each environment variable...}
>| [keys addObject: [NSString stringWithCString: {some C string}]];
>|
>| The default initializer creates an array with capacity 1, so there is a
>| lot of realloc'ing the array early on. On the third realloc
>| (capacity==4), the actual CONTENTS of the first three values of the
>| array change! As if,
>|
>| a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4
>|
>| becomes
>|
>| a[0] = 45345; a[1] = 0; a[2] = 0; a[3] = 4;
>|
>| simply due to a realloc of a (in fact a[0] takes on the value of &a[4]).
>| Does anyone have any ideas what would cause this? Solaris has
>| problems with word alignment, but I don't see that happening here.
>| Just changing the initialization to
Are you sure that the returned pointer is used as the new array pointer ?
I've found such a bug in libxml.
"realloc() returns a pointer to the newly allocated memory,
which is suitably aligned for any kind of variable and may
be different from ptr"
BTW, where is defined GC_REALLOC ?
Manuel
--
______________________________________________________________________
Manuel Guesdon - OXYMIUM <mguesdon@oxymium.net>
14 rue Jean-Baptiste Clement - 93200 Saint-Denis - France
Tel: +33 1 4940 0999 - Fax: +33 1 4940 0998