Fix potential crash in getColor functions

If the index is out of range, just return black.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-01-18 14:35:31 -08:00
parent 2c6830c399
commit 733108b473
2 changed files with 6 additions and 2 deletions

View file

@ -45,7 +45,9 @@ QString dpGasToStr(const divedatapoint& p)
QColor getColor(const color_indice_t i)
{
return profile_color[i].at(0);
if ( profile_color.count() > i && i >= 0)
return profile_color[i].at(0);
return QColor(Qt::black);
}
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();

View file

@ -58,5 +58,7 @@ void fill_profile_color()
QColor getColor(const color_indice_t i, bool isGrayscale = false)
{
return profile_color[i].at((isGrayscale) ? 1 : 0);
if (profile_color.count() > i && i >= 0)
return profile_color[i].at((isGrayscale) ? 1 : 0);
return QColor(Qt::black);
}