Skip to content

Commit

Permalink
Merge pull request #10654 from rouault/anBandMap_init
Browse files Browse the repository at this point in the history
GDALDataset: move initialization of m_poPrivate->m_anBandMap to SetBand()
  • Loading branch information
rouault authored Aug 27, 2024
2 parents c09fd95 + 6aa2e57 commit f51490a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,15 @@ void GDALDataset::SetBand(int nNewBand, GDALRasterBand *poBand)
papoBands[i] = nullptr;

nBands = std::max(nBands, nNewBand);

if (m_poPrivate)
{
for (int i = static_cast<int>(m_poPrivate->m_anBandMap.size());
i < nBands; ++i)
{
m_poPrivate->m_anBandMap.push_back(i + 1);
}
}
}

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -2781,13 +2790,7 @@ CPLErr GDALDataset::RasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
{
if (!m_poPrivate)
return CE_Failure;
const int nOldBandMapSize =
static_cast<int>(m_poPrivate->m_anBandMap.size());
if (nOldBandMapSize < nBandCount)
{
for (int i = nOldBandMapSize; i < nBandCount; ++i)
m_poPrivate->m_anBandMap.push_back(i + 1);
}
CPLAssert(static_cast<int>(m_poPrivate->m_anBandMap.size()) == nBands);
panBandMap = m_poPrivate->m_anBandMap.data();
}

Expand Down

0 comments on commit f51490a

Please sign in to comment.