diff --git a/src/App/Enumeration.cpp b/src/App/Enumeration.cpp index 5a7ad0546f..8f138f0870 100644 --- a/src/App/Enumeration.cpp +++ b/src/App/Enumeration.cpp @@ -100,7 +100,9 @@ void Enumeration::setEnums(const char **plEnums) std::string oldValue; bool preserve = (isValid() && plEnums != NULL); if (preserve) { - oldValue = getCStr(); + const char* str = getCStr(); + if (str) + oldValue = str; } // set _ownEnumArray @@ -126,7 +128,9 @@ void Enumeration::setEnums(const std::vector &values) std::string oldValue; bool preserve = isValid(); if (preserve) { - oldValue = getCStr(); + const char* str = getCStr(); + if (str) + oldValue = str; } if (isValid() && _ownEnumArray) { @@ -165,7 +169,7 @@ void Enumeration::setValue(const char *value) return; } - unsigned int i = 0; + int i = 0; const char **plEnums = _EnumArray; // search for the right entry @@ -322,7 +326,10 @@ void Enumeration::findMaxVal(void) } const char **plEnums = _EnumArray; - long i = 0; + + // the NULL terminator doesn't belong to the range of + // valid values + int i = -1; while (*(plEnums++) != NULL) { ++i; // very unlikely to have enums with more then 5000 entries! diff --git a/src/App/Enumeration.h b/src/App/Enumeration.h index 5fb3724645..e25324ba6e 100644 --- a/src/App/Enumeration.h +++ b/src/App/Enumeration.h @@ -143,7 +143,7 @@ namespace App /*! * Returns -1 if the enumeration is not valid according to isValid() */ - int maxValue(void) const {return _maxVal;}; + int maxValue(void) const {return _maxVal;} /// Assignment operator Enumeration & operator=(const Enumeration &other); @@ -161,7 +161,7 @@ namespace App bool operator==(const char *other) const; protected: /// Returns true if instance was not initialized via static string list - bool isCustom(void) const {return _ownEnumArray;}; + bool isCustom(void) const {return _ownEnumArray;} /// Updates _maxVal void findMaxVal(void);