mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue