mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
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:
parent
5727555328
commit
e1b32b96e9
3 changed files with 66 additions and 37 deletions
|
@ -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>
|
Thu Mar 16 11:37:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSRange.m: NSRangeFromString() bugfix by karl@nfox.com
|
* Source/NSRange.m: NSRangeFromString() bugfix by karl@nfox.com
|
||||||
|
|
|
@ -849,39 +849,51 @@ static inline void
|
||||||
stringIncrementCountAndMakeHoleAt(NSGMutableCStringStruct *self,
|
stringIncrementCountAndMakeHoleAt(NSGMutableCStringStruct *self,
|
||||||
int index, int size)
|
int index, int size)
|
||||||
{
|
{
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
if (self->_count > 0)
|
||||||
|
{
|
||||||
#ifndef STABLE_MEMCPY
|
#ifndef STABLE_MEMCPY
|
||||||
{
|
unsigned i = self->_count;
|
||||||
unsigned i = self->_count;
|
|
||||||
|
|
||||||
while (i-- > index)
|
while (i-- > index)
|
||||||
self->_contents_chars[i+size] = self->_contents_chars[i];
|
{
|
||||||
}
|
self->_contents_chars[i+size] = self->_contents_chars[i];
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
memcpy(self->_contents_chars + index,
|
memcpy(self->_contents_chars + index,
|
||||||
self->_contents_chars + index + size,
|
self->_contents_chars + index + size,
|
||||||
self->_count - index);
|
self->_count - index);
|
||||||
#endif /* STABLE_MEMCPY */
|
#endif /* STABLE_MEMCPY */
|
||||||
(self->_count) += size;
|
}
|
||||||
(self->_hash) = 0;
|
self->_count += size;
|
||||||
|
self->_hash = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
||||||
int index, int size)
|
int index, int size)
|
||||||
{
|
{
|
||||||
(self->_count) -= size;
|
if (size > 0)
|
||||||
|
{
|
||||||
|
self->_count -= size;
|
||||||
#ifndef STABLE_MEMCPY
|
#ifndef STABLE_MEMCPY
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = index; i <= self->_count; i++)
|
|
||||||
self->_contents_chars[i] = self->_contents_chars[i+size];
|
for (i = index; i <= self->_count; i++)
|
||||||
}
|
{
|
||||||
|
self->_contents_chars[i] = self->_contents_chars[i+size];
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
memcpy(self->_contents_chars + index + size,
|
memcpy(self->_contents_chars + index + size,
|
||||||
self->_contents_chars + index,
|
self->_contents_chars + index,
|
||||||
self->_count - index);
|
self->_count - index);
|
||||||
#endif /* STABLE_MEMCPY */
|
#endif /* STABLE_MEMCPY */
|
||||||
(self->_hash) = 0;
|
self->_hash = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the designated initializer for this class */
|
/* This is the designated initializer for this class */
|
||||||
|
|
|
@ -536,47 +536,58 @@ static inline void
|
||||||
stringIncrementCountAndMakeHoleAt(NSGMutableStringStruct *self,
|
stringIncrementCountAndMakeHoleAt(NSGMutableStringStruct *self,
|
||||||
int index, int size)
|
int index, int size)
|
||||||
{
|
{
|
||||||
if (self->_count || size)
|
if (size > 0)
|
||||||
|
{
|
||||||
|
if (self->_count > 0)
|
||||||
{
|
{
|
||||||
NSCAssert(index+size<=self->_count,@"index+size>length");
|
NSCAssert(index+size<=self->_count,@"index+size>length");
|
||||||
NSCAssert(self->_count+size<=self->_capacity,@"length+size>capacity");
|
NSCAssert(self->_count+size<=self->_capacity,@"length+size>capacity");
|
||||||
#ifndef STABLE_MEMCPY
|
#ifndef STABLE_MEMCPY
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = self->_count; i >= index; i--)
|
|
||||||
self->_contents_chars[i+size] = self->_contents_chars[i];
|
for (i = self->_count; i >= index; i--)
|
||||||
|
{
|
||||||
|
self->_contents_chars[i+size] = self->_contents_chars[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
memcpy(self->_contents_chars + index,
|
memcpy(self->_contents_chars + index,
|
||||||
self->_contents_chars + index + size,
|
self->_contents_chars + index + size, 2*(self->_count - index));
|
||||||
2*(self->_count - index));
|
|
||||||
#endif /* STABLE_MEMCPY */
|
#endif /* STABLE_MEMCPY */
|
||||||
(self->_count) += size;
|
self->_count += size;
|
||||||
};
|
}
|
||||||
(self->_hash) = 0;
|
self->_hash = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
|
stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
|
||||||
int index, int size)
|
int index, int size)
|
||||||
{
|
{
|
||||||
if (self->_count || size)
|
if (size > 0)
|
||||||
|
{
|
||||||
|
if (self->_count > 0)
|
||||||
{
|
{
|
||||||
NSCAssert(index+size<=self->_count,@"index+size>length");
|
NSCAssert(index+size<=self->_count,@"index+size>length");
|
||||||
(self->_count) -= size;
|
self->_count -= size;
|
||||||
#ifndef STABLE_MEMCPY
|
#ifndef STABLE_MEMCPY
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = index; i <= self->_count; i++)
|
|
||||||
self->_contents_chars[i] = self->_contents_chars[i+size];
|
for (i = index; i <= self->_count; i++)
|
||||||
|
{
|
||||||
|
self->_contents_chars[i] = self->_contents_chars[i+size];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
memcpy(self->_contents_chars + index + size,
|
memcpy(self->_contents_chars + index + size,
|
||||||
self->_contents_chars + index,
|
self->_contents_chars + index,
|
||||||
2*(self->_count - index));
|
2*(self->_count - index));
|
||||||
#endif // STABLE_MEMCPY
|
#endif // STABLE_MEMCPY
|
||||||
};
|
}
|
||||||
(self->_hash) = 0;
|
self->_hash = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializing Newly Allocated Strings
|
// Initializing Newly Allocated Strings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue