Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::min with proper cast #585

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions encfs/ConfigVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<int>(bytes, pd->buffer.size() - pd->offset);

if (toCopy > 0) {
memcpy(buffer_, pd->buffer.data() + pd->offset, toCopy);
Expand Down
10 changes: 3 additions & 7 deletions encfs/SSL_Cipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(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<int>(niv, mds - offset);
if (toCopy != 0) {
memcpy(iv, mdBuf + offset, toCopy);
iv += toCopy;
Expand Down Expand Up @@ -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<int>(sizeof(revBuf), bytesLeft);

for (int i = 0; i < toFlip; ++i) {
revBuf[i] = buf[toFlip - (i + 1)];
Expand Down
4 changes: 0 additions & 4 deletions encfs/encfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down