Skip to content

Commit de6533b

Browse files
authored
Merge pull request #214 from MarkLee131/fix/getcolumnnames-empty-label-row
fix GetColumnNames() undefined behavior on empty label row
2 parents 30271a0 + 7f3b333 commit de6533b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/rapidcsv.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,9 +1473,13 @@ namespace rapidcsv
14731473
{
14741474
if (mLabelParams.mColumnNameIdx >= 0)
14751475
{
1476-
return std::vector<std::string>(mData.at(static_cast<size_t>(mLabelParams.mColumnNameIdx)).begin() +
1477-
(mLabelParams.mRowNameIdx + 1),
1478-
mData.at(static_cast<size_t>(mLabelParams.mColumnNameIdx)).end());
1476+
const auto& labelRow = mData.at(static_cast<size_t>(mLabelParams.mColumnNameIdx));
1477+
const size_t offset = static_cast<size_t>(mLabelParams.mRowNameIdx + 1);
1478+
if (offset <= labelRow.size())
1479+
{
1480+
return std::vector<std::string>(labelRow.begin() + static_cast<int>(offset),
1481+
labelRow.end());
1482+
}
14791483
}
14801484

14811485
return std::vector<std::string>();

0 commit comments

Comments
 (0)