avoid possible problem with replacement when there's nothing to do ... we could be unnecessarily checking that a buffer exists when we don't actually need to

move anything in it.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37537 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2014-01-05 17:30:11 +00:00
parent 2d306c7aa5
commit 66ec6af49b

View file

@ -2066,7 +2066,7 @@ failure:
if (aRange.location > size) if (aRange.location > size)
{ {
[NSException raise: NSRangeException [NSException raise: NSRangeException
format: @"location bad in replaceByteInRange:withBytes:"]; format: @"location bad in %@", NSStringFromSelector(_cmd)];
} }
if (aRange.length > 0) if (aRange.length > 0)
{ {
@ -2080,7 +2080,7 @@ failure:
if (0 == buf) if (0 == buf)
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"missing bytes in replaceBytesInRange:withBytes:"]; format: @"missing bytes in %@", NSStringFromSelector(_cmd)];
} }
memmove(buf + aRange.location, bytes, aRange.length); memmove(buf + aRange.location, bytes, aRange.length);
} }
@ -2104,7 +2104,11 @@ failure:
if (aRange.location > size) if (aRange.location > size)
{ {
[NSException raise: NSRangeException [NSException raise: NSRangeException
format: @"location bad in replaceByteInRange:withBytes:length:"]; format: @"location bad in %@", NSStringFromSelector(_cmd)];
}
if (0 == length && 0 == shift)
{
return; // Nothing to do
} }
if (need > size) if (need > size)
{ {
@ -2114,7 +2118,7 @@ failure:
if (0 == buf) if (0 == buf)
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"missing bytes in replaceByteInRange:withBytes:length:"]; format: @"missing bytes in %@", NSStringFromSelector(_cmd)];
} }
if (shift < 0) if (shift < 0)
{ {