diff --git a/samples/cpp/common/utils/include/samples/classification_results.h b/samples/cpp/common/utils/include/samples/classification_results.h index ee0aace9c0b..d2cebc138f3 100644 --- a/samples/cpp/common/utils/include/samples/classification_results.h +++ b/samples/cpp/common/utils/include/samples/classification_results.h @@ -223,6 +223,7 @@ public: */ void show() { /** Print the result iterating over each batch **/ + std::ios::fmtflags fmt(std::cout.flags()); std::cout << std::endl << "Top " << _nTop << " results:" << std::endl << std::endl; for (unsigned int image_id = 0; image_id < _batchSize; ++image_id) { std::wstring out(_imageNames[image_id].begin(), _imageNames[image_id].end()); @@ -248,10 +249,12 @@ public: } std::cout << std::endl; } + std::cout.flags(fmt); } void print() { /** Print the result iterating over each batch **/ + std::ios::fmtflags fmt(std::cout.flags()); std::cout << std::endl << "Top " << _nTop << " results:" << std::endl << std::endl; for (unsigned int image_id = 0; image_id < _batchSize; ++image_id) { std::wstring out(_imageNames[image_id].begin(), _imageNames[image_id].end()); @@ -287,6 +290,7 @@ public: } std::cout << std::endl; } + std::cout.flags(fmt); } /** diff --git a/samples/cpp/common/utils/include/samples/common.hpp b/samples/cpp/common/utils/include/samples/common.hpp index 5eb47e68161..c2dc8252923 100644 --- a/samples/cpp/common/utils/include/samples/common.hpp +++ b/samples/cpp/common/utils/include/samples/common.hpp @@ -593,6 +593,7 @@ static UNUSED void printPerformanceCounts( if (bshowHeader) { stream << std::endl << "performance counts:" << std::endl << std::endl; } + std::ios::fmtflags fmt(std::cout.flags()); auto performanceMapSorted = perfCountersSorted(performanceMap); @@ -629,6 +630,7 @@ static UNUSED void printPerformanceCounts( std::cout << std::endl; std::cout << "Full device name: " << deviceName << std::endl; std::cout << std::endl; + std::cout.flags(fmt); } static UNUSED void printPerformanceCounts(InferenceEngine::InferRequest request, diff --git a/samples/cpp/speech_sample/main.cpp b/samples/cpp/speech_sample/main.cpp index 1cf391f009e..a0e73ce44b4 100644 --- a/samples/cpp/speech_sample/main.cpp +++ b/samples/cpp/speech_sample/main.cpp @@ -307,6 +307,9 @@ void printPerformanceCounters( std::string fullDeviceName, const uint64_t numberOfFramesOnHw) { #if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) && !defined(_M_ARM64) + if (numberOfFrames == 0) + throw std::runtime_error("printPerformanceCounters: numberOfFrames=0, incorrect input"); + std::ios::fmtflags fmt(std::cout.flags()); stream << std::endl << "Performance counts:" << std::endl; stream << std::setw(10) << std::right << "" << "Counter descriptions"; @@ -340,6 +343,7 @@ void printPerformanceCounters( stream << "Number of frames delivered to GNA HW: " << numberOfFramesOnHw; stream << "/" << numberOfFrames; stream << std::endl; + std::cout.flags(fmt); #endif } diff --git a/thirdparty/cnpy/cnpy.cpp b/thirdparty/cnpy/cnpy.cpp index 859f898210a..ca04cbc0808 100644 --- a/thirdparty/cnpy/cnpy.cpp +++ b/thirdparty/cnpy/cnpy.cpp @@ -224,6 +224,7 @@ cnpy::NpyArray load_the_npz_array(FILE* fp, uint32_t compr_bytes, uint32_t uncom d_stream.opaque = Z_NULL; d_stream.avail_in = 0; d_stream.next_in = Z_NULL; + d_stream.total_in = 0; d_stream.total_out = 0; err = inflateInit2(&d_stream, -MAX_WBITS); @@ -332,8 +333,8 @@ cnpy::NpyArray cnpy::npz_load(std::string fname, std::string varname) { //read in the extra field uint16_t extra_field_len = *(uint16_t*) &local_header[28]; - fseek(fp,extra_field_len,SEEK_CUR); //skip past the extra field - + if (fseek(fp,extra_field_len,SEEK_CUR) != 0) //skip past the extra field + throw std::runtime_error("npz_load: failed fseek"); uint16_t compr_method = *reinterpret_cast(&local_header[0]+8); uint32_t compr_bytes = *reinterpret_cast(&local_header[0]+18); uint32_t uncompr_bytes = *reinterpret_cast(&local_header[0]+22); diff --git a/thirdparty/cnpy/cnpy.h b/thirdparty/cnpy/cnpy.h index 40b959a6a8a..1eaa338b2b3 100644 --- a/thirdparty/cnpy/cnpy.h +++ b/thirdparty/cnpy/cnpy.h @@ -163,7 +163,8 @@ namespace cnpy { fclose(fp); throw std::runtime_error("npz_save: header read error while adding to existing zip"); } - fseek(fp,global_header_offset,SEEK_SET); + if(fseek(fp,global_header_offset,SEEK_SET) != 0) + throw std::runtime_error("npz_save: failed fseek"); } else { fp = fopen(zipname.c_str(),"wb");