mirror of
https://github.com/vgough/encfs.git
synced 2024-11-25 01:13:12 +01:00
Use std::min with proper cast (#585)
This commit is contained in:
parent
ee47e2fc14
commit
44fa4630e1
@ -27,10 +27,6 @@
|
|||||||
|
|
||||||
namespace encfs {
|
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() : pd(new ConfigVarData) { pd->offset = 0; }
|
||||||
|
|
||||||
ConfigVar::ConfigVar(const std::string &buf) : pd(new ConfigVarData) {
|
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; }
|
void ConfigVar::resetOffset() { pd->offset = 0; }
|
||||||
|
|
||||||
int ConfigVar::read(unsigned char *buffer_, int bytes) const {
|
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) {
|
if (toCopy > 0) {
|
||||||
memcpy(buffer_, pd->buffer.data() + pd->offset, toCopy);
|
memcpy(buffer_, pd->buffer.data() + pd->offset, toCopy);
|
||||||
|
@ -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 MAX_IVLENGTH = 16; // 128 bit (AES block size, Blowfish has 64)
|
||||||
const int KEY_CHECKSUM_BYTES = 4;
|
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
|
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
|
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 offset = 0;
|
||||||
int toCopy = MIN(nkey, mds - offset);
|
int toCopy = std::min<int>(nkey, mds - offset);
|
||||||
if (toCopy != 0) {
|
if (toCopy != 0) {
|
||||||
memcpy(key, mdBuf + offset, toCopy);
|
memcpy(key, mdBuf + offset, toCopy);
|
||||||
key += toCopy;
|
key += toCopy;
|
||||||
nkey -= toCopy;
|
nkey -= toCopy;
|
||||||
offset += toCopy;
|
offset += toCopy;
|
||||||
}
|
}
|
||||||
toCopy = MIN(niv, mds - offset);
|
toCopy = std::min<int>(niv, mds - offset);
|
||||||
if (toCopy != 0) {
|
if (toCopy != 0) {
|
||||||
memcpy(iv, mdBuf + offset, toCopy);
|
memcpy(iv, mdBuf + offset, toCopy);
|
||||||
iv += toCopy;
|
iv += toCopy;
|
||||||
@ -760,7 +756,7 @@ static void flipBytes(unsigned char *buf, int size) {
|
|||||||
|
|
||||||
int bytesLeft = size;
|
int bytesLeft = size;
|
||||||
while (bytesLeft != 0) {
|
while (bytesLeft != 0) {
|
||||||
int toFlip = MIN(sizeof(revBuf), bytesLeft);
|
int toFlip = std::min<int>(sizeof(revBuf), bytesLeft);
|
||||||
|
|
||||||
for (int i = 0; i < toFlip; ++i) {
|
for (int i = 0; i < toFlip; ++i) {
|
||||||
revBuf[i] = buf[toFlip - (i + 1)];
|
revBuf[i] = buf[toFlip - (i + 1)];
|
||||||
|
@ -54,10 +54,6 @@
|
|||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
#include "fuse.h"
|
#include "fuse.h"
|
||||||
|
|
||||||
#ifndef MIN
|
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ESUCCESS 0
|
#define ESUCCESS 0
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
Loading…
Reference in New Issue
Block a user