From 4161099b91952c7d76705d1b088e829c5746830f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Sat, 8 Sep 2018 23:29:14 +0200 Subject: [PATCH] Fix warnings reported by MSVC --- include/exiv2/types.hpp | 2 ++ src/bigtiffimage.cpp | 13 +++++++------ src/convert.cpp | 2 +- src/http.cpp | 14 +++++++------- src/pngchunk_int.cpp | 12 ++++++------ src/preview.cpp | 2 +- unitTests/gtestwrapper.h | 1 + unitTests/test_types.cpp | 2 +- 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/include/exiv2/types.hpp b/include/exiv2/types.hpp index 06767ddc..c9fa74d2 100644 --- a/include/exiv2/types.hpp +++ b/include/exiv2/types.hpp @@ -555,6 +555,8 @@ namespace Exiv2 { // IntType may be a user-defined type). #ifdef _MSC_VER #pragma warning( disable : 4146 ) +#undef max +#undef min #endif if (n < zero) { if (n == std::numeric_limits::min()) { diff --git a/src/bigtiffimage.cpp b/src/bigtiffimage.cpp index aa45f71b..500fb97f 100644 --- a/src/bigtiffimage.cpp +++ b/src/bigtiffimage.cpp @@ -370,13 +370,14 @@ namespace Exiv2 bytes[jump]=0 ; if ( ::strcmp("Nikon",chars) == 0 ) { - // tag is an embedded tiff - std::vector nikon_bytes(count-jump); + // tag is an embedded tiff + std::vector nikon_bytes(count - jump); - io.read(&nikon_bytes.at(0),nikon_bytes.size()); - MemIo memIo(&nikon_bytes.at(0),(long)count-jump); // create a file - std::cerr << "Nikon makernote" << std::endl; - // printTiffStructure(memIo,out,option,depth); TODO: fix it + io.read(&nikon_bytes.at(0), (long)nikon_bytes.size()); + MemIo memIo(&nikon_bytes.at(0), (long)count - jump); // create a file + std::cerr << "Nikon makernote" << std::endl; + // printTiffStructure(memIo,out,option,depth); + // TODO: fix it } else { diff --git a/src/convert.cpp b/src/convert.cpp index 0dde3d56..e41c57a7 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -1551,7 +1551,7 @@ namespace { &inbytesleft, &outptr, &outbytesleft); - int outbytesProduced = sizeof(outbuf) - outbytesleft; + const size_t outbytesProduced = sizeof(outbuf) - outbytesleft; if (rc == size_t(-1) && errno != E2BIG) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "iconv: " << strError() diff --git a/src/http.cpp b/src/http.cpp index ce1801f3..17b9b28e 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -155,9 +155,9 @@ static int error(std::string& errors, const char* msg, const char* x, const char char buffer[buffer_size]; memset(buffer, 0, buffer_size); #ifdef MSDEV_2003 - sprintf(buffer,msg,x,y,z); + sprintf(buffer,msg,x,y,z); #else - snprintf(buffer, buffer_size, msg, x, y, z) ; + snprintf(buffer, buffer_size, msg, x, y, z) ; #endif if ( errno ) { perror(buffer) ; @@ -268,7 +268,7 @@ int Exiv2::http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::stri //////////////////////////////////// // open the socket - int sockfd = socket(AF_INET , SOCK_STREAM,IPPROTO_TCP) ; + int sockfd = (int) socket(AF_INET , SOCK_STREAM,IPPROTO_TCP) ; if ( sockfd < 0 ) return error(errors, "unable to create socket\n",NULL,NULL,0) ; // connect the socket to the server @@ -310,7 +310,7 @@ int Exiv2::http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::stri #else int n = snprintf(buffer,buff_l,httpTemplate,verb,page,version,servername,header) ; #endif - buffer[n] = 0 ; + buffer[n] = 0 ; response["requestheaders"]=std::string(buffer,n); @@ -392,21 +392,21 @@ int Exiv2::http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::stri if ( n != FINISH || !OK(status) ) { #ifdef MSDEV_2003 - sprintf(buffer,"wsa_error = %d,n = %d,sleep_ = %d status = %d" + sprintf(buffer,"wsa_error = %d,n = %d,sleep_ = %d status = %d" , WSAGetLastError() , n , sleep_ , status ) ; #else - snprintf(buffer,sizeof buffer,"wsa_error = %d,n = %d,sleep_ = %d status = %d" + snprintf(buffer,sizeof buffer,"wsa_error = %d,n = %d,sleep_ = %d status = %d" , WSAGetLastError() , n , sleep_ , status ) ; #endif - error(errors,buffer,NULL,NULL,0) ; + error(errors,buffer,NULL,NULL,0) ; } else if ( bSearching && OK(status) ) { if ( end ) { // we finished OK without finding headers, flush the buffer diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index f13594bd..58281b3f 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -152,7 +152,7 @@ namespace Exiv2 { // compressed string after the compression technique spec const byte* compressedText = data.pData_ + keysize + 2; - unsigned int compressedTextSize = data.size_ - keysize - 2; + long compressedTextSize = data.size_ - keysize - 2; enforce(compressedTextSize < data.size_, kerCorruptedMetadata); zlibUncompress(compressedText, compressedTextSize, arr); @@ -171,7 +171,7 @@ namespace Exiv2 { else if(type == iTXt_Chunk) { enforce(data.size_ >= Safe::add(keysize, 3), Exiv2::kerCorruptedMetadata); - const int nullSeparators = std::count(&data.pData_[keysize+3], &data.pData_[data.size_], '\0'); + const size_t nullSeparators = std::count(&data.pData_[keysize+3], &data.pData_[data.size_], '\0'); enforce(nullSeparators >= 2, Exiv2::kerCorruptedMetadata); // Extract a deflate compressed or uncompressed UTF-8 text chunk @@ -188,9 +188,9 @@ namespace Exiv2 { const size_t languageTextMaxSize = data.size_ - keysize - 3; std::string languageText = string_from_unterminated((const char*)(data.pData_ + Safe::add(keysize, 3)), languageTextMaxSize); - const unsigned int languageTextSize = static_cast(languageText.size()); + const size_t languageTextSize = languageText.size(); - enforce(data.size_ >= Safe::add(static_cast(Safe::add(keysize, 4)), languageTextSize), + enforce(data.size_ >= Safe::add(static_cast(Safe::add(keysize, 4)), languageTextSize), Exiv2::kerCorruptedMetadata); // translated keyword string after the language description std::string translatedKeyText = @@ -200,11 +200,11 @@ namespace Exiv2 { if ((compressionFlag == 0x00) || (compressionFlag == 0x01 && compressionMethod == 0x00)) { enforce(Safe::add(static_cast(keysize + 3 + languageTextSize + 1), - Safe::add(translatedKeyTextSize, 1u)) <= data.size_, + Safe::add(translatedKeyTextSize, 1u)) <= static_cast(data.size_), Exiv2::kerCorruptedMetadata); const byte* text = data.pData_ + keysize + 3 + languageTextSize + 1 + translatedKeyTextSize + 1; - const long textsize = data.size_ - (keysize + 3 + languageTextSize + 1 + translatedKeyTextSize + 1); + const long textsize = static_cast(data.size_ - (keysize + 3 + languageTextSize + 1 + translatedKeyTextSize + 1)); if (compressionFlag == 0x00) { // then it's an uncompressed iTXt chunk diff --git a/src/preview.cpp b/src/preview.cpp index 8123c111..ea748dbf 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -930,7 +930,7 @@ namespace { DataBuf decodeBase64(const std::string& src) { - const unsigned long srcSize = src.size(); + const size_t srcSize = src.size(); // create decoding table unsigned long invalid = 64; diff --git a/unitTests/gtestwrapper.h b/unitTests/gtestwrapper.h index 100f0ae8..2757163c 100644 --- a/unitTests/gtestwrapper.h +++ b/unitTests/gtestwrapper.h @@ -5,6 +5,7 @@ #pragma warning(push) #pragma warning(disable : 4251) #pragma warning(disable : 4275) + #pragma warning(disable : 4996) #endif #include #ifdef _MSC_VER diff --git a/unitTests/test_types.cpp b/unitTests/test_types.cpp index 3aeb6d25..a1924828 100644 --- a/unitTests/test_types.cpp +++ b/unitTests/test_types.cpp @@ -42,7 +42,7 @@ TEST(DataBuf, allocatesDataWithNonEmptyConstructor) TEST(Rational, floatToRationalCast) { - static const float floats[] = {0.5, 0.015, 0.0000625}; + static const float floats[] = {0.5f, 0.015f, 0.0000625f}; for (size_t i = 0; i < sizeof(floats) / sizeof(*floats); ++i) { const Rational r = floatToRationalCast(floats[i]);