diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-02-17 15:27:59 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-04-02 12:10:45 +0200 |
commit | 0f58593e32e6c2fbda7ab50bf7a3f0f747ad496a (patch) | |
tree | 0a3931c387f19df38c625da55673e9f2e5104a33 | |
parent | e140d8ca724e1a1d4eb36495608fe4dd72e9aa5f (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.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 9 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 15 |
3 files changed, 24 insertions, 2 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index e804a1ca9cc2..e816ffec4afa 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -461,6 +461,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 b54ef92a1410..509280bef874 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -6460,7 +6460,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; @@ -6473,7 +6473,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 @@ -6503,6 +6504,9 @@ bool ScDocument::HasColNotes(SCCOL nCol, SCTAB nTab) const if (!pTab) return false; + if (nCol >= MAXCOLCOUNT) + return false; + return pTab->aCol[nCol].HasCellNotes(); } @@ -6546,6 +6550,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 2ffc8cbba787..de7e249ca491 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1596,6 +1596,21 @@ ScPostIt* ScTable::ReleaseNote( SCCOL nCol, SCROW nRow ) return aCol[nCol].ReleaseNote(nRow); } +ScPostIt* ScTable::GetNote( SCCOL nCol, SCROW nRow ) +{ + if (!ValidCol(nCol) || nCol >= MAXCOLCOUNT) + 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)) |