diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp index ce633c6f0..6e5e73d4b 100644 --- a/parameter/SelectionCriterionType.cpp +++ b/parameter/SelectionCriterionType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -30,6 +30,8 @@ #include "SelectionCriterionType.h" #include "Tokenizer.h" +#include + #define base CElement const std::string CSelectionCriterionType::_strDelimiter = "|"; @@ -51,6 +53,18 @@ std::string CSelectionCriterionType::getKind() const // From ISelectionCriterionTypeInterface bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strValue) { + // An inclusive criterion is implemented as a bitfield over an int and + // thus, can't have values larger than the number of bits in an int. + static const unsigned int inclusiveCriterionMaxValue = 1 << (sizeof(iValue) * CHAR_BIT - 1); + + if (_bInclusive && (unsigned int)iValue > inclusiveCriterionMaxValue) { + + log_warning("Rejecting value pair association: 0x%X - %s " + "because an inclusive criterion can't have values larger than 0x%X", + iValue, strValue.c_str(), inclusiveCriterionMaxValue); + return false; + } + // Check 1 bit set only for inclusive types if (_bInclusive && (!iValue || (iValue & (iValue - 1)))) { diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 6e67b3a55..9ccac1ba9 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -333,14 +333,6 @@ bool CTestPlatform::createInclusiveSelectionCriterionFromStateList( assert(pCriterionType != NULL); uint32_t uiNbStates = remoteCommand.getArgumentCount() - 1; - - if (uiNbStates > 32) { - - strResult = "Maximum number of states for inclusive criterion is 32"; - - return false; - } - uint32_t uiState; for (uiState = 0; uiState < uiNbStates; uiState++) { @@ -397,13 +389,6 @@ bool CTestPlatform::createInclusiveSelectionCriterion(const string& strName, ISelectionCriterionTypeInterface* pCriterionType = _pParameterMgrPlatformConnector->createSelectionCriterionType(true); - if (uiNbStates > 32) { - - strResult = "Maximum number of states for inclusive criterion is 32"; - - return false; - } - uint32_t uiState; for (uiState = 0; uiState < uiNbStates; uiState++) {