summaryrefslogtreecommitdiffstats
path: root/parameter/ParameterType.h
diff options
context:
space:
mode:
authorDmitry Shkurko <Dmitry.V.Shkurko@intel.com>2013-08-28 19:33:24 +0700
committerDavid Wagner <david.wagner@intel.com>2014-02-12 17:04:12 +0100
commit764ff429ac913567910e4acb1da98502f246754a (patch)
tree9c56b38f8bf48b2a969dbe38460c399548f85624 /parameter/ParameterType.h
parent9b275887f7891890c15d07e5aa90fcf2ed846bbf (diff)
downloadexternal_parameter-framework-764ff429ac913567910e4acb1da98502f246754a.zip
external_parameter-framework-764ff429ac913567910e4acb1da98502f246754a.tar.gz
external_parameter-framework-764ff429ac913567910e4acb1da98502f246754a.tar.bz2
Avoid integer overflow while calculating max values
BZ: 134249 The behavior is undefined in the case of signed integer overflow for enum and fixed point parameter types. Modify the behavior to handle correctly the signed integers. Change-Id: Idbd0798a39f826853ae1afcd05cebd897675b9a8 Signed-off-by: Dmitry Shkurko <Dmitry.V.Shkurko@intel.com>
Diffstat (limited to 'parameter/ParameterType.h')
-rw-r--r--parameter/ParameterType.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/parameter/ParameterType.h b/parameter/ParameterType.h
index d83dbce..ed30ac3 100644
--- a/parameter/ParameterType.h
+++ b/parameter/ParameterType.h
@@ -25,6 +25,7 @@
#pragma once
#include <stdint.h>
+#include <limits>
#include "TypeElement.h"
@@ -87,6 +88,15 @@ protected:
// Remove all bits set outside available range
uint32_t makeEncodable(uint32_t uiData) const;
+ /** Compute max value according to the parameter type */
+ template <typename type>
+ type getMaxValue() const
+ {
+ return getSize() < sizeof(type) ?
+ (static_cast<type>(1) << (getSize() * numeric_limits<unsigned char>::digits - 1)) - 1 :
+ numeric_limits<type>::max();
+ }
+
private:
// Instantiation
virtual CInstanceConfigurableElement* doInstantiate() const;