Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lvstring: fix size handling #538

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions crengine/include/lvstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,10 @@ class lString8
void reset( size_type size );
/// returns character count
size_type length() const { return pchunk->len; }
/// returns buffer size
size_type size() const { return pchunk->len; }
/// changes buffer size
void resize(size_type count = 0, value_type e = 0);
/// returns maximum number of chars that can fit into buffer
size_type capacity() const { return pchunk->size-1; }
size_type capacity() const { return pchunk->size; }
/// reserve space for specified amount of chars
void reserve(size_type count = 0);
/// returns true if string is empty
Expand Down Expand Up @@ -839,12 +837,10 @@ class lString32
void reset( size_type size );
/// returns string length, in characters
size_type length() const { return pchunk->len; }
/// returns string length, in characters
size_type size() const { return pchunk->len; }
/// resizes string buffer, appends with specified character if buffer is being extended
void resize(size_type count = 0, value_type e = 0);
/// returns string buffer size
size_type capacity() const { return pchunk->size-1; }
size_type capacity() const { return pchunk->size; }
/// ensures string buffer can hold at least count characters
void reserve(size_type count = 0);
/// erase all extra characters from end of string after size
Expand Down
40 changes: 20 additions & 20 deletions crengine/src/lvstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,11 @@ lString32 & lString32::assign(const lChar32 * str)
size_type len = _lStr_len(str);
if (pchunk->nref==1)
{
if (pchunk->size<=len)
if (pchunk->size < len)
{
// resize is necessary
pchunk->buf32 = (lChar32*) ::realloc( pchunk->buf32, sizeof(lChar32)*(len+1) );
pchunk->size = len+1;
pchunk->size = len;
}
}
else
Expand All @@ -655,11 +655,11 @@ lString32 & lString32::assign(const lChar8 * str)
size_type len = _lStr_len(str);
if (pchunk->nref==1)
{
if (pchunk->size<=len)
if (pchunk->size < len)
{
// resize is necessary
pchunk->buf32 = (lChar32*) ::realloc( pchunk->buf32, sizeof(lChar32)*(len+1) );
pchunk->size = len+1;
pchunk->size = len;
}
}
else
Expand All @@ -684,11 +684,11 @@ lString32 & lString32::assign(const lChar32 * str, size_type count)
size_type len = _lStr_nlen(str, count);
if (pchunk->nref==1)
{
if (pchunk->size<=len)
if (pchunk->size < len)
{
// resize is necessary
pchunk->buf32 = (lChar32*) ::realloc( pchunk->buf32, sizeof(lChar32)*(len+1) );
pchunk->size = len+1;
pchunk->size = len;
}
}
else
Expand All @@ -713,11 +713,11 @@ lString32 & lString32::assign(const lChar8 * str, size_type count)
size_type len = _lStr_nlen(str, count);
if (pchunk->nref==1)
{
if (pchunk->size<=len)
if (pchunk->size < len)
{
// resize is necessary
pchunk->buf32 = (lChar32*) ::realloc( pchunk->buf32, sizeof(lChar32)*(len+1) );
pchunk->size = len+1;
pchunk->size = len;
}
}
else
Expand Down Expand Up @@ -758,11 +758,11 @@ lString32 & lString32::assign(const lString32 & str, size_type offset, size_type
{
if (pchunk->nref==1)
{
if (pchunk->size<=count)
if (pchunk->size < count)
{
// resize is necessary
pchunk->buf32 = (lChar32*) ::realloc( pchunk->buf32, sizeof(lChar32)*(count+1) );
pchunk->size = count+1;
pchunk->size = count;
}
}
else
Expand Down Expand Up @@ -858,7 +858,7 @@ void lString32::reset( size_type size )
void lString32::resize(size_type n, lChar32 e)
{
lock( n );
if (n>=pchunk->size)
if (pchunk->size < n)
{
pchunk->buf32 = (lChar32*) ::realloc( pchunk->buf32, sizeof(lChar32)*(n+1) );
pchunk->size = n;
Expand Down Expand Up @@ -973,7 +973,7 @@ lString32 lString32::substr(size_type pos, size_type n) const

lString32 & lString32::pack()
{
if (pchunk->len + 4 < pchunk->size )
if (pchunk->len < pchunk->size)
{
if (pchunk->nref>1)
{
Expand Down Expand Up @@ -1784,11 +1784,11 @@ lString8 & lString8::assign(const lChar8 * str)
size_type len = _lStr_len(str);
if (pchunk->nref==1)
{
if (pchunk->size<=len)
if (pchunk->size < len)
{
// resize is necessary
pchunk->buf8 = (lChar8*) ::realloc( pchunk->buf8, sizeof(lChar8)*(len+1) );
pchunk->size = len+1;
pchunk->size = len;
}
}
else
Expand All @@ -1813,11 +1813,11 @@ lString8 & lString8::assign(const lChar8 * str, size_type count)
size_type len = _lStr_nlen(str, count);
if (pchunk->nref==1)
{
if (pchunk->size<=len)
if (pchunk->size < len)
{
// resize is necessary
pchunk->buf8 = (lChar8*) ::realloc( pchunk->buf8, sizeof(lChar8)*(len+1) );
pchunk->size = len+1;
pchunk->size = len;
}
}
else
Expand Down Expand Up @@ -1858,11 +1858,11 @@ lString8 & lString8::assign(const lString8 & str, size_type offset, size_type co
{
if (pchunk->nref==1)
{
if (pchunk->size<=count)
if (pchunk->size < count)
{
// resize is necessary
pchunk->buf8 = (lChar8*) ::realloc( pchunk->buf8, sizeof(lChar8)*(count+1) );
pchunk->size = count+1;
pchunk->size = count;
}
}
else
Expand Down Expand Up @@ -1958,7 +1958,7 @@ void lString8::reset( size_type size )
void lString8::resize(size_type n, lChar8 e)
{
lock( n );
if (n>=pchunk->size)
if (pchunk->size < n)
{
pchunk->buf8 = (lChar8*) ::realloc( pchunk->buf8, sizeof(lChar8)*(n+1) );
pchunk->size = n;
Expand Down Expand Up @@ -2448,7 +2448,7 @@ int lString32::pos(lString32 subStr) const

lString8 & lString8::pack()
{
if (pchunk->len + 4 < pchunk->size )
if (pchunk->len < pchunk->size)
{
if (pchunk->nref>1)
{
Expand Down
Loading