bugfix initialising mutable string.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16667 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-05-07 13:15:15 +00:00
parent f07090eb44
commit dc23cb8a10
2 changed files with 35 additions and 8 deletions

View file

@ -1,3 +1,9 @@
2003-05-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: ([-initWithCStringNocopy:length:freeWhenDone:])
check encodings and convert to unicode if necessary. Thanks to
Alaxander for pointing out bug.
2003-05-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: Fix call to GSFormat() to append to a mutable

View file

@ -424,7 +424,7 @@ setup(void)
{
self = [self initWithCharactersNoCopy: u length: l freeWhenDone: YES];
}
if (flag == YES)
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
@ -2860,20 +2860,36 @@ transmute(ivars self, NSString *aString)
return self;
}
- (id) initWithCStringNoCopy: (char*)byteString
- (id) initWithCStringNoCopy: (char*)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag
{
_count = length;
_capacity = length;
_contents.c = byteString;
_flags.wide = 0;
if (flag == YES && byteString != 0)
if (defEnc == intEnc)
{
unichar *u = 0;
unsigned l = 0;
if (GSToUnicode(&u, &l, chars, length, defEnc, GSObjCZone(self), 0) == NO)
{
DESTROY(self);
}
else
{
self = [self initWithCharactersNoCopy: u length: l freeWhenDone: YES];
}
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return self;
}
if (flag == YES && chars != 0)
{
#if GS_WITH_GC
_zone = GSAtomicMallocZone();
#else
_zone = NSZoneFromPointer(byteString);
_zone = NSZoneFromPointer(chars);
#endif
_flags.free = 1;
}
@ -2881,6 +2897,11 @@ transmute(ivars self, NSString *aString)
{
_zone = 0;
}
_count = length;
_capacity = length;
_contents.c = chars;
_flags.wide = 0;
return self;
}