From f3b7bf3d6b36d09aaec991978557cbd76bf46da4 Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Tue, 12 May 2020 16:04:26 +0900 Subject: [PATCH] Check if inference target types are valid or not Change-Id: I8ad50b13b7377dde306d052267705f5465062c32 Signed-off-by: Inki Dae --- src/inference_engine_common_impl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/inference_engine_common_impl.cpp b/src/inference_engine_common_impl.cpp index d85e5c4..50dac93 100755 --- a/src/inference_engine_common_impl.cpp +++ b/src/inference_engine_common_impl.cpp @@ -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"); -- 2.34.1