From 44fa4630e141cbda64df37fbe4a6db97430e85ce Mon Sep 17 00:00:00 2001 From: Ben RUBSON <6764151+benrubson@users.noreply.github.com> Date: Wed, 26 Feb 2020 19:38:43 +0100 Subject: [PATCH] Use std::min with proper cast (#585) --- encfs/ConfigVar.cpp | 6 +----- encfs/SSL_Cipher.cpp | 10 +++------- encfs/encfs.cpp | 4 ---- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/encfs/ConfigVar.cpp b/encfs/ConfigVar.cpp index 8d3343b..23368c7 100644 --- a/encfs/ConfigVar.cpp +++ b/encfs/ConfigVar.cpp @@ -27,10 +27,6 @@ namespace encfs { -#ifndef MIN -inline int MIN(int a, int b) { return (a < b) ? a : b; } -#endif - ConfigVar::ConfigVar() : pd(new ConfigVarData) { pd->offset = 0; } ConfigVar::ConfigVar(const std::string &buf) : pd(new ConfigVarData) { @@ -54,7 +50,7 @@ ConfigVar &ConfigVar::operator=(const ConfigVar &src) { void ConfigVar::resetOffset() { pd->offset = 0; } int ConfigVar::read(unsigned char *buffer_, int bytes) const { - int toCopy = MIN(bytes, pd->buffer.size() - pd->offset); + int toCopy = std::min(bytes, pd->buffer.size() - pd->offset); if (toCopy > 0) { memcpy(buffer_, pd->buffer.data() + pd->offset, toCopy); diff --git a/encfs/SSL_Cipher.cpp b/encfs/SSL_Cipher.cpp index d39a39c..20dee8b 100644 --- a/encfs/SSL_Cipher.cpp +++ b/encfs/SSL_Cipher.cpp @@ -48,10 +48,6 @@ const int MAX_KEYLENGTH = 32; // in bytes (256 bit) const int MAX_IVLENGTH = 16; // 128 bit (AES block size, Blowfish has 64) const int KEY_CHECKSUM_BYTES = 4; -#ifndef MIN -inline int MIN(int a, int b) { return (a < b) ? a : b; } -#endif - /** This produces the same result as OpenSSL's EVP_BytesToKey. The difference is that here we can explicitly specify the key size, instead of relying on @@ -94,14 +90,14 @@ int BytesToKey(int keyLen, int ivLen, const EVP_MD *md, } int offset = 0; - int toCopy = MIN(nkey, mds - offset); + int toCopy = std::min(nkey, mds - offset); if (toCopy != 0) { memcpy(key, mdBuf + offset, toCopy); key += toCopy; nkey -= toCopy; offset += toCopy; } - toCopy = MIN(niv, mds - offset); + toCopy = std::min(niv, mds - offset); if (toCopy != 0) { memcpy(iv, mdBuf + offset, toCopy); iv += toCopy; @@ -760,7 +756,7 @@ static void flipBytes(unsigned char *buf, int size) { int bytesLeft = size; while (bytesLeft != 0) { - int toFlip = MIN(sizeof(revBuf), bytesLeft); + int toFlip = std::min(sizeof(revBuf), bytesLeft); for (int i = 0; i < toFlip; ++i) { revBuf[i] = buf[toFlip - (i + 1)]; diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index a7c9c34..e324425 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -54,10 +54,6 @@ #include "FileUtils.h" #include "fuse.h" -#ifndef MIN -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif - #define ESUCCESS 0 using namespace std;