Skip to content

Commit 653952f

Browse files
authored
Fix an assertion in EB (#4569)
The assertion itself could go out of bound. So we should test the vector's size first.
1 parent d8b5ace commit 653952f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Src/EB/AMReX_EBDataCollection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ EBDataCollection::EBDataCollection (const EB2::Level& a_level,
2323

2424
if (m_support >= EBSupport::basic)
2525
{
26+
AMREX_ALWAYS_ASSERT(!m_ngrow.empty());
27+
2628
m_cellflags = new FabArray<EBCellFlagFab>(a_ba, a_dm, 1, m_ngrow[0], MFInfo(),
2729
DefaultFabFactory<EBCellFlagFab>());
2830
a_level.fillEBCellFlag(*m_cellflags, m_geom);
@@ -33,7 +35,7 @@ EBDataCollection::EBDataCollection (const EB2::Level& a_level,
3335

3436
if (m_support >= EBSupport::volume)
3537
{
36-
AMREX_ALWAYS_ASSERT(m_ngrow[1] <= m_ngrow[0]);
38+
AMREX_ALWAYS_ASSERT((m_ngrow.size() >= 2) && (m_ngrow[1] <= m_ngrow[0]));
3739

3840
m_volfrac = new MultiFab(a_ba, a_dm, 1, m_ngrow[1], MFInfo(), FArrayBoxFactory());
3941
a_level.fillVolFrac(*m_volfrac, m_geom);
@@ -44,7 +46,7 @@ EBDataCollection::EBDataCollection (const EB2::Level& a_level,
4446

4547
if (m_support == EBSupport::full)
4648
{
47-
AMREX_ALWAYS_ASSERT(m_ngrow[2] <= m_ngrow[0]);
49+
AMREX_ALWAYS_ASSERT((m_ngrow.size() >= 3) && (m_ngrow[2] <= m_ngrow[0]));
4850

4951
const int ng = m_ngrow[2];
5052

0 commit comments

Comments
 (0)