Undefined Behavior sanitizer fixes [2022/2] (#12339)
* UBSan errors fix * Cleanup
This commit is contained in:
@@ -119,7 +119,7 @@ bool directory_exists(const std::string& path);
|
||||
* @param[in] path The file name
|
||||
* @return file size
|
||||
*/
|
||||
inline uint64_t file_size(const char* path) {
|
||||
inline int64_t file_size(const char* path) {
|
||||
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||
std::wstring widefilename = ov::util::string_to_wstring(path);
|
||||
const wchar_t* file_name = widefilename.c_str();
|
||||
@@ -143,7 +143,7 @@ inline uint64_t file_size(const char* path) {
|
||||
* @param[in] path The file name
|
||||
* @return file size
|
||||
*/
|
||||
inline uint64_t file_size(const std::wstring& path) {
|
||||
inline int64_t file_size(const std::wstring& path) {
|
||||
return file_size(wstring_to_string(path).c_str());
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ inline uint64_t file_size(const std::wstring& path) {
|
||||
* @param[in] path The file name
|
||||
* @return file size
|
||||
*/
|
||||
inline uint64_t file_size(const std::string& path) {
|
||||
inline int64_t file_size(const std::string& path) {
|
||||
return file_size(path.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,22 +28,22 @@ int64_t calculate_num_spatial(const ConvType* op,
|
||||
num_spatial = filters_rank.get_length() - num_non_spatial_filter_dims;
|
||||
|
||||
if (const auto &size = op->m_dilations.size()) {
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == size,
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == static_cast<int64_t>(size),
|
||||
"Dilations should be defined for all and only spatial dimensions.");
|
||||
num_spatial = static_cast<int64_t>(size);
|
||||
}
|
||||
if (const auto &size = op->m_strides.size()) {
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == size,
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == static_cast<int64_t>(size),
|
||||
"Strides should be defined for all and only spatial dimensions.");
|
||||
num_spatial = static_cast<int64_t>(size);
|
||||
}
|
||||
if (const auto &size = op->m_pads_begin.size()) {
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == size,
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == static_cast<int64_t>(size),
|
||||
"Pads begin should be defined for all and only spatial dimensions.");
|
||||
num_spatial = static_cast<int64_t>(size);
|
||||
}
|
||||
if (const auto &size = op->m_pads_end.size()) {
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == size,
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == static_cast<int64_t>(size),
|
||||
"Pads begin should be defined for all and only spatial dimensions.");
|
||||
num_spatial = static_cast<int64_t>(size);
|
||||
}
|
||||
@@ -349,7 +349,7 @@ int64_t calculate_num_spatial(const ConvType* op,
|
||||
num_spatial = calculate_num_spatial(
|
||||
op, input_shape, filters_shape, num_non_spatial_data_dims, num_non_spatial_filter_dims);
|
||||
if (const auto &size = op->m_output_padding.size()) {
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == size,
|
||||
NODE_VALIDATION_CHECK(op, num_spatial == -1 || num_spatial == static_cast<int64_t>(size),
|
||||
"Output padding should be defined for all and only spatial dimensions.");
|
||||
num_spatial = static_cast<int64_t>(size);
|
||||
}
|
||||
|
||||
@@ -308,8 +308,8 @@ void op::v0::LSTMSequence::validate_and_infer_types() {
|
||||
auto merged_num_directions = Dimension::dynamic();
|
||||
auto result_et = element::dynamic;
|
||||
|
||||
// Copy all inputs without peephole and initial_cell_state information for further
|
||||
// validation
|
||||
NODE_VALIDATION_CHECK(this, get_input_size() > 0, "The number of inputs of the LSTMSequence op cannot be zero.");
|
||||
// Copy all inputs without peephole and initial_cell_state information for further validation
|
||||
for (size_t i = 0; i < get_input_size() - 1; i++) {
|
||||
// exclude initial_cell_state from the loop
|
||||
if (i != 2) {
|
||||
|
||||
@@ -550,7 +550,7 @@ GenericLayerParams XmlDeserializer::parseGenericParams(const pugi::xml_node& nod
|
||||
bool input) -> GenericLayerParams::LayerPortData {
|
||||
GenericLayerParams::LayerPortData port;
|
||||
|
||||
port.portId = XMLParseUtils::GetIntAttr(parentNode, "id");
|
||||
port.portId = XMLParseUtils::GetUIntAttr(parentNode, "id");
|
||||
|
||||
FOREACH_CHILD (node, parentNode, "dim") {
|
||||
int64_t dim = 0;
|
||||
@@ -590,7 +590,7 @@ GenericLayerParams XmlDeserializer::parseGenericParams(const pugi::xml_node& nod
|
||||
};
|
||||
GenericLayerParams params;
|
||||
|
||||
params.layerId = XMLParseUtils::GetIntAttr(node, "id");
|
||||
params.layerId = XMLParseUtils::GetUIntAttr(node, "id");
|
||||
params.version = XMLParseUtils::GetStrAttr(node, "version");
|
||||
|
||||
params.type = XMLParseUtils::GetStrAttr(node, "type");
|
||||
|
||||
@@ -71,7 +71,7 @@ bool is_correct_onnx_field(const PbKey& decoded_key) {
|
||||
* Each consecutive varint byte needs to be left-shifted "7 x its position in the vector"
|
||||
* and bitwise added to the accumulator afterward.
|
||||
*/
|
||||
uint32_t varint_bytes_to_number(const std::vector<char>& bytes) {
|
||||
uint32_t varint_bytes_to_number(const std::vector<uint8_t>& bytes) {
|
||||
uint32_t accumulator = 0u;
|
||||
|
||||
for (size_t i = 0; i < bytes.size(); ++i) {
|
||||
@@ -84,7 +84,7 @@ uint32_t varint_bytes_to_number(const std::vector<char>& bytes) {
|
||||
}
|
||||
|
||||
uint32_t decode_varint(std::istream& model) {
|
||||
std::vector<char> bytes;
|
||||
std::vector<uint8_t> bytes;
|
||||
// max 4 bytes for a single value because this function returns a 32-bit long decoded varint
|
||||
const size_t MAX_VARINT_BYTES = 4u;
|
||||
// optimization to avoid allocations during push_back calls
|
||||
@@ -96,7 +96,7 @@ uint32_t decode_varint(std::istream& model) {
|
||||
// keep reading all bytes which have the MSB on from the stream
|
||||
while (key_component & 0x80 && bytes.size() < MAX_VARINT_BYTES) {
|
||||
// drop the most significant bit
|
||||
const char component = key_component & ~0x80;
|
||||
const uint8_t component = key_component & ~0x80;
|
||||
bytes.push_back(component);
|
||||
model.get(key_component);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user