Check if inference target types are valid or not 12/233112/1
authorInki Dae <inki.dae@samsung.com>
Tue, 12 May 2020 07:04:26 +0000 (16:04 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 12 May 2020 07:41:30 +0000 (16:41 +0900)
Change-Id: I8ad50b13b7377dde306d052267705f5465062c32
Signed-off-by: Inki Dae <inki.dae@samsung.com>
src/inference_engine_common_impl.cpp

index d85e5c4c31c45d38a1d9aa580620616eeed63d81..50dac93511884068682cc837fff1bc4b9433412b 100755 (executable)
@@ -35,6 +35,7 @@ extern "C" {
 #define LOG_TAG "INFERENCE_ENGINE_COMMON"
 }
 
+#define INFERENCE_TARGET_TYPE_MASK     (INFERENCE_TARGET_CPU | INFERENCE_TARGET_GPU | INFERENCE_TARGET_CUSTOM)
 #define CHECK_ENGINE_INSTANCE(object)                                          \
        if (object == nullptr) {                                                                \
                LOGE("Inference engine handle is null.");                       \
@@ -238,6 +239,11 @@ int InferenceEngineCommon::SetTargetDevices(int types)
 {
        CHECK_ENGINE_INSTANCE(mBackendHandle);
 
+       if (INFERENCE_TARGET_NONE >= types || INFERENCE_TARGET_TYPE_MASK < types) {
+               LOGE("Given target device types(%d) are invalid.", types);
+               return INFERENCE_ENGINE_ERROR_INVALID_PARAMETER;
+       }
+
     int ret = mBackendHandle->SetTargetDevices(types);
     if (ret != INFERENCE_ENGINE_ERROR_NONE)
         LOGE("Fail to SetTargetDevice");