Minor range check fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6295 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-03-17 08:49:46 +00:00
parent b597cab253
commit 0781dc0250
3 changed files with 66 additions and 37 deletions

View file

@ -1,3 +1,9 @@
Fri Mar 17 07:47:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSGString.m: Add checks to safely (and more efficiently)
handle deletion and insertion of zero-length ranges.
* Source/NSGCString.m: ditto.
Thu Mar 16 11:37:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSRange.m: NSRangeFromString() bugfix by karl@nfox.com

View file

@ -849,39 +849,51 @@ static inline void
stringIncrementCountAndMakeHoleAt(NSGMutableCStringStruct *self,
int index, int size)
{
if (size > 0)
{
if (self->_count > 0)
{
#ifndef STABLE_MEMCPY
{
unsigned i = self->_count;
unsigned i = self->_count;
while (i-- > index)
self->_contents_chars[i+size] = self->_contents_chars[i];
}
while (i-- > index)
{
self->_contents_chars[i+size] = self->_contents_chars[i];
}
#else
memcpy(self->_contents_chars + index,
self->_contents_chars + index + size,
self->_count - index);
memcpy(self->_contents_chars + index,
self->_contents_chars + index + size,
self->_count - index);
#endif /* STABLE_MEMCPY */
(self->_count) += size;
(self->_hash) = 0;
}
self->_count += size;
self->_hash = 0;
}
}
static inline void
stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
int index, int size)
{
(self->_count) -= size;
if (size > 0)
{
self->_count -= size;
#ifndef STABLE_MEMCPY
{
int i;
for (i = index; i <= self->_count; i++)
self->_contents_chars[i] = self->_contents_chars[i+size];
}
{
int i;
for (i = index; i <= self->_count; i++)
{
self->_contents_chars[i] = self->_contents_chars[i+size];
}
}
#else
memcpy(self->_contents_chars + index + size,
self->_contents_chars + index,
self->_count - index);
memcpy(self->_contents_chars + index + size,
self->_contents_chars + index,
self->_count - index);
#endif /* STABLE_MEMCPY */
(self->_hash) = 0;
self->_hash = 0;
}
}
/* This is the designated initializer for this class */

View file

@ -536,47 +536,58 @@ static inline void
stringIncrementCountAndMakeHoleAt(NSGMutableStringStruct *self,
int index, int size)
{
if (self->_count || size)
if (size > 0)
{
if (self->_count > 0)
{
NSCAssert(index+size<=self->_count,@"index+size>length");
NSCAssert(self->_count+size<=self->_capacity,@"length+size>capacity");
#ifndef STABLE_MEMCPY
{
int i;
for (i = self->_count; i >= index; i--)
self->_contents_chars[i+size] = self->_contents_chars[i];
int i;
for (i = self->_count; i >= index; i--)
{
self->_contents_chars[i+size] = self->_contents_chars[i];
}
}
#else
memcpy(self->_contents_chars + index,
self->_contents_chars + index + size,
2*(self->_count - index));
memcpy(self->_contents_chars + index,
self->_contents_chars + index + size, 2*(self->_count - index));
#endif /* STABLE_MEMCPY */
(self->_count) += size;
};
(self->_hash) = 0;
self->_count += size;
}
self->_hash = 0;
}
}
static inline void
stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
int index, int size)
{
if (self->_count || size)
if (size > 0)
{
if (self->_count > 0)
{
NSCAssert(index+size<=self->_count,@"index+size>length");
(self->_count) -= size;
self->_count -= size;
#ifndef STABLE_MEMCPY
{
int i;
for (i = index; i <= self->_count; i++)
self->_contents_chars[i] = self->_contents_chars[i+size];
int i;
for (i = index; i <= self->_count; i++)
{
self->_contents_chars[i] = self->_contents_chars[i+size];
}
}
#else
memcpy(self->_contents_chars + index + size,
self->_contents_chars + index,
2*(self->_count - index));
#endif // STABLE_MEMCPY
};
(self->_hash) = 0;
}
self->_hash = 0;
}
}
// Initializing Newly Allocated Strings