Half-assed attempt at enforcing operator [] preconditions
...inspired by comments to <https://gerrit.libreoffice.org/#/c/3068/> "String::AppendAscii cleanup in dbaccess," but it quickly becomes apparent that lots of code rely on s[s.getLength()] == 0, so live with a weakened precondition check for now. Change-Id: Ifad96c706b14433df4a084ab8054b32433b8b5b6
This commit is contained in:
@@ -194,7 +194,8 @@ sal_Bool LngParser::Merge(
|
||||
{
|
||||
rtl::OString sLine( *(*pLines)[ nPos ] );
|
||||
sLine = sLine.trim();
|
||||
if (( sLine[0] == '[' ) &&
|
||||
if (!sLine.isEmpty() &&
|
||||
( sLine[0] == '[' ) &&
|
||||
( sLine[sLine.getLength() - 1] == ']' ))
|
||||
{
|
||||
sGroup = getBracketedContent(sLine).trim();
|
||||
@@ -220,7 +221,8 @@ sal_Bool LngParser::Merge(
|
||||
{
|
||||
rtl::OString sLine( *(*pLines)[ nPos ] );
|
||||
sLine = sLine.trim();
|
||||
if (( sLine[0] == '[' ) &&
|
||||
if (!sLine.isEmpty() &&
|
||||
( sLine[0] == '[' ) &&
|
||||
( sLine[sLine.getLength() - 1] == ']' ))
|
||||
{
|
||||
sGroup = getBracketedContent(sLine).trim();
|
||||
|
@@ -388,7 +388,14 @@ public:
|
||||
|
||||
@since LibreOffice 3.5
|
||||
*/
|
||||
sal_Char operator [](sal_Int32 index) const { return getStr()[index]; }
|
||||
sal_Char operator [](sal_Int32 index) const {
|
||||
assert(index >= 0 && index <= getLength());
|
||||
//TODO: should really check for < getLength(), but there is quite
|
||||
// some clever code out there that violates this function's
|
||||
// documented precondition and relies on s[s.getLength()] == 0 and
|
||||
// that would need to be fixed first
|
||||
return getStr()[index];
|
||||
}
|
||||
|
||||
/**
|
||||
Compares two strings.
|
||||
|
@@ -474,7 +474,14 @@ public:
|
||||
|
||||
@since LibreOffice 3.5
|
||||
*/
|
||||
sal_Unicode operator [](sal_Int32 index) const { return getStr()[index]; }
|
||||
sal_Unicode operator [](sal_Int32 index) const {
|
||||
assert(index >= 0 && index <= getLength());
|
||||
//TODO: should really check for < getLength(), but there is quite
|
||||
// some clever code out there that violates this function's
|
||||
// documented precondition and relies on s[s.getLength()] == 0 and
|
||||
// that would need to be fixed first
|
||||
return getStr()[index];
|
||||
}
|
||||
|
||||
/**
|
||||
Compares two strings.
|
||||
|
Reference in New Issue
Block a user