X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=inference-engine%2Fsrc%2Finference_engine%2Fxml_parse_utils.cpp;h=a8d955ce9b297ec8c258d9086a41382d30c6ff30;hb=0ef92871b6dd9a9ceed16d184c4595d2618d526f;hp=a833eebadf0cd2d75d0f6a718e9a3b653165c588;hpb=866530fb047cd17af6bd2dbbde5f5cb35f876840;p=platform%2Fupstream%2Fdldt.git diff --git a/inference-engine/src/inference_engine/xml_parse_utils.cpp b/inference-engine/src/inference_engine/xml_parse_utils.cpp index a833eeb..a8d955c 100644 --- a/inference-engine/src/inference_engine/xml_parse_utils.cpp +++ b/inference-engine/src/inference_engine/xml_parse_utils.cpp @@ -1,31 +1,56 @@ -// Copyright (C) 2018 Intel Corporation -// +// Copyright (C) 2018-2019 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #include "xml_parse_utils.h" #include "details/ie_exception.hpp" #include "ie_precision.hpp" +#include +#include int XMLParseUtils::GetIntAttr(const pugi::xml_node &node, const char *str) { auto attr = node.attribute(str); if (attr.empty()) THROW_IE_EXCEPTION << "node <" << node.name() << "> is missing mandatory attribute: " << str << " at offset " << node.offset_debug(); - return atoi(attr.value()); + std::string str_value = std::string(attr.value()); + std::size_t idx = 0; + int int_value = std::stoi(str_value, &idx, 10); + if (idx != str_value.length()) + THROW_IE_EXCEPTION << "node <" << node.name() << "> has attribute \"" << str << "\" = \"" << str_value + << "\" which is not an integer" << " at offset " + << node.offset_debug(); + return int_value; } +uint64_t XMLParseUtils::GetUInt64Attr(const pugi::xml_node &node, const char *str) { + auto attr = node.attribute(str); + if (attr.empty()) + THROW_IE_EXCEPTION << "node <" << node.name() << "> is missing mandatory attribute: " << str << " at offset " + << node.offset_debug(); + std::string str_value = std::string(attr.value()); + std::size_t idx = 0; + long long int_value = std::stoll(str_value, &idx, 10); + if (idx != str_value.length() || int_value < 0) + THROW_IE_EXCEPTION << "node <" << node.name() << "> has attribute \"" << str << "\" = \"" << str_value + << "\" which is not an unsigned 64 bit integer" << " at offset " + << node.offset_debug(); + return static_cast(int_value); +} unsigned int XMLParseUtils::GetUIntAttr(const pugi::xml_node &node, const char *str) { auto attr = node.attribute(str); if (attr.empty()) THROW_IE_EXCEPTION << "node <" << node.name() << "> is missing mandatory attribute: " << str << " at offset " << node.offset_debug(); - int value = atoi(attr.value()); - if (value < 0) - THROW_IE_EXCEPTION << "node <" << node.name() << "> has incorrect parameter: " << str << " at offset " + std::string str_value = std::string(attr.value()); + std::size_t idx = 0; + long long int_value = std::stoll(str_value, &idx, 10); + if (idx != str_value.length() || int_value < 0 || int_value > (std::numeric_limits::max)()) + THROW_IE_EXCEPTION << "node <" << node.name() << "> has attribute \"" << str << "\" = \"" << str_value + << "\" which is not an unsigned integer" << " at offset " << node.offset_debug(); - return static_cast(value); + return static_cast(int_value); } std::string XMLParseUtils::GetStrAttr(const pugi::xml_node &node, const char *str) { @@ -47,7 +72,14 @@ float XMLParseUtils::GetFloatAttr(const pugi::xml_node &node, const char *str) { if (attr.empty()) THROW_IE_EXCEPTION << "node <" << node.name() << "> is missing mandatory attribute: " << str << " at offset " << node.offset_debug(); - return static_cast(atof(attr.value())); + std::string str_value = std::string(attr.value()); + std::size_t idx = 0; + float float_value = std::stof(str_value, &idx); + if (idx != str_value.length()) + THROW_IE_EXCEPTION << "node <" << node.name() << "> has attribute \"" << str << "\" = \"" << str_value + << "\" which is not a floating point" << " at offset " + << node.offset_debug(); + return float_value; } InferenceEngine::Precision XMLParseUtils::GetPrecisionAttr(const pugi::xml_node &node, const char *str) { @@ -68,23 +100,25 @@ InferenceEngine::Precision XMLParseUtils::GetPrecisionAttr(const pugi::xml_node int XMLParseUtils::GetIntAttr(const pugi::xml_node &node, const char *str, int defVal) { auto attr = node.attribute(str); if (attr.empty()) return defVal; - return atoi(attr.value()); + return GetIntAttr(node, str); +} + +uint64_t XMLParseUtils::GetUInt64Attr(const pugi::xml_node &node, const char *str, uint64_t defVal) { + auto attr = node.attribute(str); + if (attr.empty()) return defVal; + return GetUInt64Attr(node, str); } unsigned int XMLParseUtils::GetUIntAttr(const pugi::xml_node &node, const char *str, unsigned int defVal) { auto attr = node.attribute(str); if (attr.empty()) return defVal; - int value = atoi(attr.value()); - if (value < 0) - THROW_IE_EXCEPTION << "node <" << node.name() << "> has incorrect parameter: " << str << " at offset " - << node.offset_debug(); - return static_cast(value); + return GetUIntAttr(node, str); } float XMLParseUtils::GetFloatAttr(const pugi::xml_node &node, const char *str, float defVal) { auto attr = node.attribute(str); if (attr.empty()) return defVal; - return static_cast(atof(attr.value())); + return GetFloatAttr(node, str); } int XMLParseUtils::GetIntChild(const pugi::xml_node &node, const char *str, int defVal) {