mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
ad63dfed22
commit
418907a03d
4 changed files with 46 additions and 32 deletions
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue