Skip to content

Commit

Permalink
Refs #9927 Fix array size calculation in SymbolBox.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Jul 16, 2014
1 parent b22997d commit 3df4ef3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/lib/include/SymbolBox.h
Expand Up @@ -63,6 +63,8 @@ class SymbolBox : public QComboBox
void focusInEvent(QFocusEvent *);

private:
static size_t numberOfSymbols();

static const QwtSymbol::Style symbols[];
};

Expand Down
11 changes: 8 additions & 3 deletions Code/Mantid/MantidPlot/src/lib/src/SymbolBox.cpp
Expand Up @@ -150,7 +150,7 @@ void SymbolBox::init(bool showNoSymbol)
void SymbolBox::setStyle(const QwtSymbol::Style& style)
{
// Avoid compiler warnings relating to symbols + sizeof(symbols) being out of range
size_t n = sizeof(symbols);
size_t n = numberOfSymbols();
for(size_t i = 0; i < n; ++i)
{
if (symbols[i] == style)
Expand Down Expand Up @@ -179,7 +179,7 @@ QwtSymbol::Style SymbolBox::selectedSymbol() const
int SymbolBox::symbolIndex(const QwtSymbol::Style& style)
{
// Avoid compiler warnings relating to symbols + sizeof(symbols) being out of range
size_t n = sizeof(symbols);
size_t n = numberOfSymbols();
for(size_t i = 0; i < n; ++i)
{
if (symbols[i] == style)
Expand All @@ -197,7 +197,7 @@ int SymbolBox::symbolIndex(const QwtSymbol::Style& style)

QwtSymbol::Style SymbolBox::style(int index)
{
if (index >= 0 && index < (int)sizeof(symbols))
if (index >= 0 && index < (int)numberOfSymbols())
return symbols[index];

return QwtSymbol::NoSymbol;
Expand All @@ -217,3 +217,8 @@ void SymbolBox::focusInEvent(QFocusEvent * e)
emit activated(this);
return QComboBox::focusInEvent(e);
}

size_t SymbolBox::numberOfSymbols()
{
return sizeof(symbols) / sizeof(QwtSymbol::Style);
}

0 comments on commit 3df4ef3

Please sign in to comment.