Several minor bugfixes in handling BOOL values, fix crash in shrinking

mutable data.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18507 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-01-30 11:30:56 +00:00
parent ad63dfed22
commit 418907a03d
4 changed files with 46 additions and 32 deletions

View file

@ -1742,37 +1742,45 @@ failure:
unsigned size = [self length];
unsigned end = NSMaxRange(aRange);
int shift = length - aRange.length;
unsigned need = end + shift;
unsigned need = size + shift;
void *buf;
if (aRange.location > size)
{
[NSException raise: NSRangeException
format: @"location bad in replaceByteInRange:withBytes:"];
}
if (length > aRange.length)
{
need += (length - aRange.length);
}
if (need > size)
{
[self setLength: need];
}
if (aRange.length > 0 || aRange.length != length)
buf = [self mutableBytes];
if (shift < 0)
{
void *buf = [self mutableBytes];
if (end < size && shift != 0)
if (length > 0)
{
// Copy bytes into place.
memmove(buf + aRange.location, bytes, length);
}
// Fill gap
memmove(buf + end + shift, buf + end, size - end);
}
else
{
if (shift > 0)
{
// Open space
memmove(buf + end + shift, buf + end, size - end);
}
if (length > 0)
{
// Copy bytes into place.
memmove(buf + aRange.location, bytes, length);
}
}
if (shift < 0)
if (need < size)
{
[self setLength: need + shift];
[self setLength: need];
}
}