summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-02-17 15:27:59 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2022-02-21 18:07:56 +0100
commitf9277cbbc5217219cad44c54663142042cebb3db (patch)
tree90ab525063fc876d5c091115beefc91b90f67559
parent5f2a5e7c4a63df17ec61e48c29a67febea27a7ac (diff)
fix range checking in calls like ScDocument::GetNote()
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130076 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com> (cherry picked from commit 957d99a539df6e21fd40370938ca5dab1613cf8c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130105 Reviewed-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 77bef67094579e7d0d2a515f5f8a5def8abe49e8) Change-Id: I5612e765b3484b0515f4a16030ee19133ae3126a
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/source/core/data/document.cxx9
-rw-r--r--sc/source/core/data/table2.cxx15
3 files changed, 24 insertions, 2 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index dae1f6f36eaf..e4a9d79ff86c 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -464,6 +464,8 @@ public:
void GetLastDataPos(SCCOL& rCol, SCROW& rRow) const;
ScPostIt* ReleaseNote( SCCOL nCol, SCROW nRow );
+ ScPostIt* GetNote( SCCOL nCol, SCROW nRow );
+ void SetNote( SCCOL nCol, SCROW nRow, ScPostIt* pNote );
size_t GetNoteCount( SCCOL nCol ) const;
SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 06a1a532e628..09a0b3db5819 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6448,7 +6448,7 @@ ScPostIt* ScDocument::GetNote(const ScAddress& rPos)
ScPostIt* ScDocument::GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab)
{
if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
- return maTabs[nTab]->aCol[nCol].GetCellNote(nRow);
+ return maTabs[nTab]->GetNote(nCol, nRow);
else
return nullptr;
@@ -6461,7 +6461,8 @@ void ScDocument::SetNote(const ScAddress& rPos, ScPostIt* pNote)
void ScDocument::SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, ScPostIt* pNote)
{
- return maTabs[nTab]->aCol[nCol].SetCellNote(nRow, pNote);
+ if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
+ maTabs[nTab]->SetNote(nCol, nRow, std::move(pNote));
}
bool ScDocument::HasNote(const ScAddress& rPos) const
@@ -6491,6 +6492,9 @@ bool ScDocument::HasColNotes(SCCOL nCol, SCTAB nTab) const
if (!pTab)
return false;
+ if (nCol >= pTab->GetAllocatedColumnsCount())
+ return false;
+
return pTab->aCol[nCol].HasCellNotes();
}
@@ -6534,6 +6538,7 @@ ScPostIt* ScDocument::GetOrCreateNote(const ScAddress& rPos)
else
return CreateNote(rPos);
}
+
ScPostIt* ScDocument::CreateNote(const ScAddress& rPos)
{
ScPostIt* pPostIt = new ScPostIt(*this, rPos);
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index e640b31622f4..85e3db333cd4 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1600,6 +1600,21 @@ ScPostIt* ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
return aCol[nCol].ReleaseNote(nRow);
}
+ScPostIt* ScTable::GetNote( SCCOL nCol, SCROW nRow )
+{
+ if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
+ return nullptr;
+ return aCol[nCol].GetCellNote(nRow);
+}
+
+void ScTable::SetNote( SCCOL nCol, SCROW nRow, ScPostIt* pNote )
+{
+ if (!ValidColRow(nCol, nRow))
+ return;
+
+ CreateColumnIfNotExists(nCol).SetCellNote(nRow, std::move(pNote));
+}
+
size_t ScTable::GetNoteCount( SCCOL nCol ) const
{
if (!ValidCol(nCol))